/
EERaidAdmin = LibStub("AceAddon-3.0"):NewAddon("EERaidAdmin", "AceConsole-3.0", "AceBucket-3.0", "AceEvent-3.0", "AceComm-3.0") |
------ VARIABLES |
local __EERACaption = "EERaidAdmin" |
local __EERA = "EERA" |
local __NoItem = "ÐÐµÑ ÐÑедмеÑа" |
local __UpdateRate = 0.1 |
local __IsDebugging = 0 |
local __serverOffset = nil |
local __raidActiveGroups = 5 |
local __raidActivePlayers = __raidActiveGroups * 5 |
local db |
EERaidAdmin.__IsDebugging = __IsDebugging |
EERaidAdmin.__serverOffset = __serverOffset |
EERaidAdmin.__raidActiveGroups = __raidActiveGroups |
EERaidAdmin.__raidActivePlayers = __raidActivePlayers |
------ HELPER METHODS |
local function _hex(r, g, b) |
if type(r) == "table" then |
if r.r then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end |
end |
return string.format("|cff%02x%02x%02x", r*255, g*255, b*255) |
end |
local function _color(r, g, b, msg) |
if type(r) == "table" then |
if r.r then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end |
end |
t_color = string.format("|cff%02x%02x%02x", r*255, g*255, b*255) |
if msg ~= '' then |
return t_color..msg..'|r' |
else |
return t_color |
end |
end |
local function _message(msg, label) |
local output = "" |
output = _color(0,1,1, 'EERaidAdmin: ') |
if label then |
output = output.._color(0,0.7,0.7, label..': ') |
end |
output = output..msg |
print(output) |
end |
local function _debug(msg, fatal) |
--if __IsDebugging == 1 or fatal then |
-- EELoot:Print("|cffdd0000debug: "..msg.."|r") |
--end |
end |
function EERaidAdmin:ServerDateTime() |
if __serverOffset == nil then |
local serverHour, serverMinute = GetGameTime() |
local utcHour = tonumber(date("%H")) |
local utcMinute = tonumber(date("%M")) |
local ser = serverHour + serverMinute / 60 |
local utc = utcHour + utcMinute / 60 |
__serverOffset = floor((ser - utc) * 2 + 0.5) / 2 |
if __serverOffset >= 12 then |
__serverOffset = __serverOffset - 24 |
elseif __serverOffset < -12 then |
__serverOffset = __serverOffset + 24 |
end |
end |
local t_time = time()+__serverOffset*60*60 |
local t_date = date("%Y-%m-%d %H:%M:%S", t_time) |
return t_date |
end |
function EERaidAdmin:OnCommReceived(prefix, message, distribution, sender) |
_debug("OnCommReceived") |
local tokens = { strsplit(";", message) } |
if prefix == "LSRC" then |
if tokens[1] == "C_VER" then |
-- pechataem versii klientov |
_message(sender..", "..tokens[2], "ÐеÑÑÐ¸Ñ ÐºÐ»Ð¸ÐµÐ½Ñа") |
end |
elseif prefix == "LSRA" then |
if tokens[1] == "A_VER_POLL" then |
-- otzyvaemjsa na zapros o versii adminki |
self:SendCommMessage("LSRA", "A_VER;"..GetAddOnMetadata("EERaidAdmin", "X-Curse-Packaged-Version"), "WHISPER", sender) |
elseif tokens[1] == "A_VER" then |
_message(sender..", "..tokens[2], "ÐеÑÑÐ¸Ñ Ð°Ð´Ð¼Ð¸Ð½Ð°") |
end |
end |
end |
function EERaidAdmin:ValidateTabs() |
_debug("ValidateTabs") |
local rank |
--local role |
local isML |
for i = 1, GetNumRaidMembers() do |
-- rank: Returns 2 if the raid member is the leader of the raid, 1 if the raid member is promoted to assistant, and 0 otherwise. |
-- role: The player's role within the raid ("maintank" or "mainassist"). |
local t_name, t_rank, _, _, _, _, _, _, _, t_role, t_isML = GetRaidRosterInfo(i) |
if UnitName("player") == t_name then |
rank = t_rank |
--role = t_role |
isML = t_isML |
break |
end |
end |
if UnitInRaid("player") then |
self.tab1:Enable() |
else |
self.tab1:Disable(); |
end |
self.tab2:Enable() |
self.tab3:Enable() |
end |
function EERaidAdmin:RAID_ROSTER_UPDATE() |
_debug("RAID_ROSTER_UPDATE") |
self:ValidateTabs() |
end |
function EERaidAdmin:OnInitialize() |
_debug("OnInitialize") |
self.db = LibStub("AceDB-3.0"):New("EERaidAdminDB") |
db = self.db.global |
if db.__AutoGreen == nil then db.__AutoGreen = true; end |
if db.__AutoAnnounceLoot == nil then db.__AutoAnnounceLoot = true; end |
-- register chat command |
self:RegisterChatCommand(__EERA, "ParseChatCommand") |
self:RegisterBucketEvent("RAID_ROSTER_UPDATE", 0.5, "RAID_ROSTER_UPDATE") |
self:RegisterComm("LSRC") |
self:RegisterComm("LSRA") |
self:CreateFrames() |
self.Anchor:Hide() |
PanelTemplates_SetNumTabs(self.Anchor, 3) |
PanelTemplates_TabResize(self.tab1,20) |
PanelTemplates_TabResize(self.tab2,20) |
PanelTemplates_TabResize(self.tab3,20) |
PanelTemplates_SetTab(self.Anchor, 0) |
self:ValidateTabs() |
end |
function EERaidAdmin:OnEnable() |
_debug("OnEnable") |
end |
function EERaidAdmin:OnDisable() |
_debug("OnDisable") |
end |
-- Main event handler |
function EERaidAdmin:OnEvent() |
if (event == "VARIABLES_LOADED") then |
end |
if (event == "CHAT_MSG_ADDON") then |
end |
end |
function EERaidAdmin:OnShow() |
PlaySound("UChatScrollButton") |
self:ValidateTabs() |
--PanelTemplates_SetTab(diskpContainerFrame, 1) |
--DisKP_SetTab(DisKP_SelectedTab) |
--DisKP_CheckNewBoss:SetChecked( DisKP_config["NEW_BOSS"] ) |
end |
function EERaidAdmin:CreateFrames() |
-- Anchor |
self.Anchor = CreateFrame("Frame", "EERAAnchor", UIParent) |
self.Anchor:SetFrameStrata("MEDIUM") |
self.Anchor:SetToplevel(true) |
self.Anchor:SetMovable(true) |
self.Anchor:EnableMouse(true) |
self.Anchor:SetWidth(600) |
self.Anchor:SetHeight(680) |
-- self.Anchor:SetScript("OnLoad", function() EERaidAdmin:OnLoad() end ) |
self.Anchor:SetScript("OnEvent", function() EERaidAdmin:OnEvent() end ) |
self.Anchor:SetScript("OnShow", function() EERaidAdmin:OnShow() end ) |
self.Anchor:SetScript("OnHide", function() PlaySound("UChatScrollButton") end ) |
self.Anchor:SetScript("OnMouseDown", self.Anchor.StartMoving) |
self.Anchor:SetScript("OnMouseUp", self.Anchor.StopMovingOrSizing) |
self.Anchor:SetBackdrop({ |
bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", |
edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border", |
tile=true, tileSize=32, edgeSize=32, insets={left=10, right=10, top=10, bottom=10} |
}) |
-- Caption and cancel button |
local t = self.Anchor:CreateTexture("FrameHeader") |
t:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") |
t:SetWidth(350) |
t:SetHeight(64) |
t:SetPoint("TOP",0,12) |
self.Anchor.texture = t |
local fs = self.Anchor:CreateFontString("$parentTitle","ARTWORK","GameFontNormal") |
fs:SetText(__EERACaption) |
fs:SetPoint("TOP","FrameHeader",0,-14) |
local cb = CreateFrame("Button", nil, self.Anchor, "UIPanelCloseButton") |
cb:SetPoint("TOPRIGHT",self.Anchor,-2,-3) |
-- Bottom tabs |
self.tab1 = CreateFrame("Button", "$parentTab1", self.Anchor, "CharacterFrameTabButtonTemplate" ) |
self.tab1:SetText("Рейд") |
self.tab1:SetScript("OnClick", function() |
EERaidAdmin:SetTab(1) -- TODO: |
end ) |
self.tab1:SetPoint("LEFT",self.Anchor,"BOTTOMLEFT",10,-10) |
self.tab2 = CreateFrame("Button", "$parentTab2", self.Anchor, "CharacterFrameTabButtonTemplate" ) |
self.tab2:SetText("ÐаÑма") |
self.tab2:SetScript("OnClick", function() |
EERaidAdmin:SetTab(2) |
end) |
self.tab2:SetPoint("LEFT",self.tab1,"RIGHT",-16,0) |
self.tab3 = CreateFrame("Button", "$parentTab3", self.Anchor, "CharacterFrameTabButtonTemplate" ) |
self.tab3:SetText("Ролл") |
self.tab3:SetScript("OnClick", function() |
EERaidAdmin:SetTab(3) |
end ) |
self.tab3:SetPoint("LEFT",self.tab2,"RIGHT",-16,0) |
-- Panels |
---- Raid panel |
---- |
---- Raid panel |
-- self.RaidTab = CreateFrame("Frame",nil,self.Anchor) |
-- |
-- self.StartRaid = CreateFrame("Button","CollectLootButton",self.RaidTab,"OptionsButtonTemplate") |
-- self.StartRaid:SetHeight(28) |
-- self.StartRaid:SetText("ÐолÑÑиÑÑ") |
-- self.StartRaid:SetScript("OnClick", function() |
-- EERaidAdmin:CollectLoot_OnClick() |
-- end ) |
-- self.StartRaid:SetPoint("LEFT",self.RaidTab,"TOPLEFT",20,-60) |
-- |
self.Anchor:SetClampedToScreen( true ) |
self.Anchor:SetPoint("CENTER",0,0) |
end |
function EERaidAdmin:ParseChatCommand(input) |
_debug("ParseChatCommand") |
local input = strtrim(input) |
if input ~= '' then |
-- squeeze spaces |
input = string.gsub(input, "(%s+)", " ") |
-- tokenize |
local tokens = { strsplit(" ", input) } |
-- switch |
if string.lower(tokens[1]) == "dbcreate" then |
EEKarma:DBCreate(tokens[2]) |
elseif string.lower(tokens[1]) == "dbuse" then |
EEKarma:DBUse(tokens[2]) |
elseif string.lower(tokens[1]) == "dblist" then |
EEKarma:DBList() |
elseif string.lower(tokens[1]) == "raidstart" then -- start raid |
EERaid:StartRaid() |
elseif string.lower(tokens[1]) == "raidstop" then -- end raid |
EERaid:EndRaid() |
elseif string.lower(tokens[1]) == "raidshow" then -- ??? |
EERaid:ContinueRaid() |
elseif string.lower(tokens[1]) == "loot" then -- manual loot |
local mloot = string.gsub(input, "^loot%s*", '') |
_debug("> Loot added manually " .. mloot); |
EELoot:ManualCollectLoot(mloot) |
EERaidAdmin.Anchor:Show() |
EERaidAdmin:SetTab(3) |
elseif string.lower(tokens[1]) == "dbactive" then |
if EEKarma:DBActive() then |
_message(db.ActiveDB, "ÐкÑÐ¸Ð²Ð½Ð°Ñ ÐÐ") |
else |
_debug("ÐРне опÑеделена" , 1) |
end |
elseif string.lower(tokens[1]) == "dbcompact" then |
_message("ÐÑÑаÑÑÑ ÑжаÑÑ ÐÐ") |
EEKarma:DBCompact() |
elseif string.lower(tokens[1]) == "dbprune" then |
_message("ÐÑÑаÑÑÑ ÑдалиÑÑ Ð¸Ð³Ñока из ÐÐ") |
if tokens[2] then |
EEKarma:DBPrune(tokens[2]) |
end |
elseif string.lower(tokens[1]) == "dbpruneall" then |
_message("ÐÑÑаÑÑÑ Ð¿Ð¾ÑиÑÑиÑÑ ÐÐ Ð¾Ñ Ð¿Ð»Ð¾Ñ Ð¸Ñ Ð¸Ð³Ñоков") |
EEKarma:DBPrune() |
elseif string.lower(tokens[1]) == "raidbeer" then |
self:SendCommMessage("LSRA", "BEER", "RAID") |
elseif string.lower(tokens[1]) == "guildbeer" then |
self:SendCommMessage("LSRA", "BEER", "GUILD") |
-- |
elseif string.lower(tokens[1]) == "autogreen" then |
if db.__AutoGreen == true then |
db.__AutoGreen = false |
_message( _color(0.85,0,0,"ÐÑклÑÑено"), "ÐвÑомаÑиÑеÑки подбиÑаÑÑ Ð·ÐµÐ»ÐµÐ½ÐºÑ") |
else |
db.__AutoGreen = true |
_message( _color(0,0.85,0,"ÐклÑÑено"), "ÐвÑомаÑиÑеÑки подбиÑаÑÑ Ð·ÐµÐ»ÐµÐ½ÐºÑ") |
end |
elseif string.lower(tokens[1]) == "autoannounceloot" then |
if db.__AutoAnnounceLoot == true then |
db.__AutoAnnounceLoot = false |
_message( _color(0.85,0,0,"ÐÑклÑÑено"), "ÐвÑомаÑиÑеÑкое анонÑиÑование лÑÑа") |
else |
db.__AutoAnnounceLoot = true |
_message( _color(0,0.85,0,"ÐклÑÑено"), "ÐвÑомаÑиÑеÑкое анонÑиÑование лÑÑа") |
end |
elseif string.lower(tokens[1]) == "verpoll" then |
-- stub |
if not tokens[2] then |
_message( _color(0,0.85,0,"/eera verpoll client|admin"), "Please type"); |
elseif string.lower(tokens[2]) == "client" then |
self:SendCommMessage("LSRA", "C_VER_POLL", "GUILD") |
elseif string.lower(tokens[2]) == "admin" then |
self:SendCommMessage("LSRA", "A_VER_POLL", "GUILD") |
end |
elseif string.lower(tokens[1]) == "notify" then |
if tokens[2] and (string.lower(tokens[2]) == "raid" or string.lower(tokens[2]) == "guild") then |
EEKarma:SendMassNotify(string.lower(tokens[2])) |
end |
elseif string.lower(tokens[1]) == "freeraid" then |
db._FreeRaid = not db._FreeRaid; |
_message( _color(0,0.85,0,"ÐклÑÑено"), "FreeRaid:") |
end |
else |
--_message("---- ÐейÑÑÐ²Ð¸Ñ Ñ ÐÐ --------------") |
--_message("СоздаÑÑ Ð½Ð¾Ð²ÑÑ ÐÐ", "/eera dbcreate [name]") |
--_message("ÐадейÑÑвоваÑÑ ÐÐ", "/eera dbuse [name]") |
--_message("ÐоказаÑÑ Ð°ÐºÑивнÑÑ ÐÐ", "/eera dbactive") |
--_message("ÐоказаÑÑ ÑпиÑок вÑÐµÑ ÐÐ", "/eera dblist") |
--_message("СжаÑÑ ÐÐ", "/eera dbcompact") |
--_message("УдалиÑÑ Ð¿Ð»Ð¾Ñ Ð¾Ð³Ð¾ игÑока из ÐÐ", "/eera dbprune [name]") |
--_message("УдалиÑÑ Ð¿Ð»Ð¾Ñ Ð¸Ñ Ð¸Ð³Ñоков из ÐÐ", "/eera dbpruneall") |
_message("---- ÐбÑие наÑÑÑойки ------------") |
_message("ÐвÑомаÑиÑеÑки подбиÑаÑÑ Ð·ÐµÐ»ÐµÐ½ÐºÑ", "/eera autogreen") |
_message("ÐвÑомаÑиÑеÑкое анонÑиÑование лÑÑа", "/eera autoannounceloot") |
_message("ÐомеÑÑиÑÑ Ð¸Ñем в ÑпиÑок лÑÑа", "/eera loot [itemLink]") |
--_message("---- УпÑавление Ñейдом ----------"); |
--_message("ÐаÑаÑÑ Ñейд", "/eera raidstart") |
--_message("ÐаконÑиÑÑ Ñейд", "/eera raidstop") |
--_message("ÐоказаÑÑ Ð¸Ð½Ñо о ÑекÑÑем Ñейде", "/eera raidshow") |
_message("ÐÑпÑавиÑÑ Ð¾Ð¿Ð¾Ð²ÐµÑение о колиÑеÑÑве каÑÐ¼Ñ Ð³Ð¸Ð»Ñдии/ÑейдÑ", "/eera notify [guild/raid]") |
EERaidAdmin.Anchor:Show() |
end |
end |
function EERaidAdmin:SetTab(tab) |
PanelTemplates_SetTab(self.Anchor, tab) |
if tab == 1 then |
EEKarma.Anchor:Hide() |
EELoot.Anchor:Hide() |
-- |
EERaid.Anchor:SetParent(self.Anchor) |
EERaid.Anchor:SetPoint("TOPLEFT", self.Anchor, "TOPLEFT") |
EERaid.Anchor:SetPoint("BOTTOMRIGHT", self.Anchor, "BOTTOMRIGHT") |
EERaid.Anchor:Show() |
elseif tab == 2 then |
EERaid.Anchor:Hide() |
EELoot.Anchor:Hide() |
-- |
EEKarma.Anchor:SetParent(self.Anchor) |
EEKarma.Anchor:SetPoint("TOPLEFT", self.Anchor, "TOPLEFT") |
EEKarma.Anchor:SetPoint("BOTTOMRIGHT", self.Anchor, "BOTTOMRIGHT") |
EEKarma.Anchor:Show() |
elseif tab == 3 then |
EERaid.Anchor:Hide() |
EEKarma.Anchor:Hide() |
-- |
EELoot.Anchor:SetParent(self.Anchor) |
EELoot.Anchor:SetPoint("TOPLEFT", self.Anchor, "TOPLEFT") |
EELoot.Anchor:SetPoint("BOTTOMRIGHT", self.Anchor, "BOTTOMRIGHT") |
EELoot.Anchor:Show() |
end |
self:ValidateTabs() |
end |
local debug = false |
local L = LibStub("AceLocale-3.0"):NewLocale("EERaidAdmin", "ruRU", true, debug) |
-- L["asdf"] = true |
L = LibStub("AceLocale-3.0"):NewLocale("EEKarma", "ruRU", true, debug) |
L["Available DB list"] = "СпиÑок доÑÑÑпнÑÑ ÐÐ" |
L["<AFK>"] = "ÐÑÑÑÑÑÑвÑеÑ" |
L = LibStub("AceLocale-3.0"):NewLocale("EERaid", "ruRU", true, debug) |
L = LibStub("AceLocale-3.0"):NewLocale("EELoot", "ruRU", true, debug) |
EEKarma = EERaidAdmin:NewModule("EEKarma", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0") |
local L = LibStub("AceLocale-3.0"):GetLocale("EEKarma") |
--local EPGP = LibStub("EPGP"); |
local db |
local __IsDebugging = 0 |
local __raidActiveGroups = EERaidAdmin.__raidActiveGroups |
local __raidActivePlayers = EERaidAdmin.__raidActivePlayers |
local ServerDateTime = EERaidAdmin.ServerDateTime |
local SelectedMassTarget = 1 |
local dbkarma = nil |
-- 1 - item, 2 - periodic, 3 - special |
---------- |
local function _debug(msg, fatal) |
if __IsDebugging == 1 or fatal then |
EEKarma:Print("|cffdd0000debug: "..msg.."|r") |
end |
end |
local function _color(r, g, b, msg) |
if type(r) == "table" then |
if r.r then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end |
end |
t_color = string.format("|cff%02x%02x%02x", r*255, g*255, b*255) |
if msg ~= '' then |
return t_color..msg..'|r' |
else |
return t_color |
end |
end |
local function _message(msg, label) |
local output = "" |
output = _color(0,1,1, 'EEKarma: ') |
if label then |
output = output.._color(0,0.7,0.7, label..': ') |
end |
output = output..msg |
print(output) |
end |
local function __________() |
-- ignore, IDE cheat |
end |
function EEKarma:PLAYER_TARGET_CHANGED() |
if UnitExists("target") and UnitIsPlayer("target") then |
local _, class = UnitClass("target") |
self.ButtonSingleKarma:SetText("ÐÑдаÑÑ ".._color(RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b, UnitName("target"))) |
self.ButtonSingleKarma:Enable() |
else |
self.ButtonSingleKarma:SetText("ÐÐµÑ Ñели") |
self.ButtonSingleKarma:Disable() |
end |
local size = self.ButtonSingleKarma:GetTextWidth()+30 |
if size < 80 then |
size = 80 |
end |
self.ButtonSingleKarma:SetWidth(size) |
end |
local function __________() |
-- ignore, IDE cheat |
end |
function EEKarma:KarmaParseString(karmastring) |
_debug("KarmaParseString") |
if not karmastring then _debug("> ÐÐ»Ð¾Ñ Ð¾Ð¹ аÑгÑменÑ: karmastring", 1); return false; end |
if karmastring ~= 'dirty' then |
local t_date, t_type, t_karma, t_message = strsplit(";", karmastring, 4) |
t_type = tonumber(t_type) |
t_karma = tonumber(t_karma) |
return t_date, t_type, t_karma, t_message |
else |
return nil |
end |
end |
function EEKarma:KarmaGetTotal(player) |
_debug("KarmaGet") |
local ep, gp, main = EPGP:GetEPGP(player); |
if (not ep or not gp) then |
return 0; |
elseif (gp < 50) then |
return 1; |
else |
--_debug("KarmaGet: "..(floor(ep/gp)), 1) |
return floor(ep/gp); |
end; |
end |
function EEKarma:KarmaAdd(player, karma, karmatype, message, verbose) |
-- _debug("KarmaAdd for"..player.." karma: "..karma.."; message: "..message, 1) |
-- checks |
if not player then _debug("> ÐÐ»Ð¾Ñ Ð¾Ð¹ аÑгÑменÑ: player", 1); return false; end |
if not karma then _debug("> ÐÐ»Ð¾Ñ Ð¾Ð¹ аÑгÑменÑ: karma", 1); return false; end |
if not karmatype then _debug("> ÐÐ»Ð¾Ñ Ð¾Ð¹ аÑгÑменÑ: karmatype", 1); return false; end |
if not message then _debug("> ÐÐ»Ð¾Ñ Ð¾Ð¹ аÑгÑменÑ: message", 1); return false; end |
local player, karma, karmatype, message = strtrim(player), strtrim(karma), strtrim(karmatype), strtrim(message) |
if not string.find(karma, "^%s*[+-]*[%d]+%s*$") then _debug(">> каÑма должна бÑÑÑ ÑиÑлом", 1); return false; end |
if not string.find(karmatype, "^%s*[%d]+%s*$") then _debug(">> Ñип каÑÐ¼Ñ Ð´Ð¾Ð»Ð¶ÐµÐ½ бÑÑÑ ÑиÑлом", 1); return false; end |
if strlen(message) == 0 then _debug(">> комменÑаÑий обÑзаÑелен", 1); return false; end |
karma = tonumber(karma); |
karmatype = tonumber(karmatype); |
-- Saving EPGP record |
-- for ep,gp in gmatch(epgpString, "(%d+),(%d+)") do |
-- _debug("> find player "..player.." "..ep..":"..gp, 1) |
if (karmatype == 1) then -- NEED MAIN (Use GP) |
EPGP:IncGPBy(player, message, karma); |
elseif (karmatype == 2) then -- NEED OFF (Use EP) |
EPGP:IncEPBy(player, message, -karma); |
elseif (karmatype == 3) then -- DisEnchant |
-- ?? |
elseif (karmatype == 0 and not (karma == 0)) then -- Wrong GREED |
_message("wrong choise for non zero EP/GP for "..player, "Error") |
else -- GREED (Free) |
-- EPGP:IncEPBy(player, message, 0); |
end |
--local ep, gp, main = EPGP:GetEPGP(player); |
--_debug("> new player "..player.." EPGP is "..ep.."/"..gp) |
return true |
end |
function EEKarma:KarmaMassAdd(target, karma, karmatype, message) |
_debug("KarmaMassAdd") |
---------- Validations |
if not target then _debug("> Ð¿Ð»Ð¾Ñ Ð¾Ð¹ аÑгÑменÑ: target", 1); return false; end |
if not karma then _debug("> Ð¿Ð»Ð¾Ñ Ð¾Ð¹ аÑгÑменÑ: karma", 1); return false; end |
if not karmatype then _debug("> Ð¿Ð»Ð¾Ñ Ð¾Ð¹ аÑгÑменÑ: karmatype", 1); return false; end |
if not message then _debug("> Ð¿Ð»Ð¾Ñ Ð¾Ð¹ аÑгÑменÑ: message", 1); return false; end |
local target = string.lower(target) |
local karma = karma |
local karmatype = karmatype |
local message = message |
if target ~= "guild" and target ~= "raid" then _debug("> invalid target", 1); return false; end |
if not string.find(karma, "^%s*[+-]*[%d]+%s*$") then _debug(">> каÑма должна бÑÑÑ ÑиÑлом", 1); return false; end |
if not string.find(karmatype, "^%s*[%d]+%s*$") then _debug(">> Ñип каÑÐ¼Ñ Ð´Ð¾Ð»Ð¶ÐµÐ½ бÑÑÑ ÑиÑлом", 1); return false; end |
if strlen(message) == 0 then _debug(">> комменÑаÑий обÑзаÑелен", 1); return false; end |
karma = tonumber(karma) |
karmatype = tonumber(karmatype) |
if target == "guild" then |
_message(target..", "..karma..", "..message, "ÐаÑма вÑдана") |
for i = 1, GetNumGuildMembers(true) do |
local name, _, _, _, _, _, _, _, online, status, _ = GetGuildRosterInfo(i) |
if online then -- OK OK and status ~= L["<AFK>"] |
self:KarmaAdd(name, karma, karmatype, message, false) |
end |
end |
else |
_message(target..", "..karma..", "..message, "ÐаÑма вÑдана") |
for i = 1, GetNumRaidMembers() do |
local name, _, _, _, _, _, _, online, _, _, _ = GetRaidRosterInfo(i) |
if online then |
self:KarmaAdd(name, karma, karmatype, message, false) |
end |
end |
end |
return true |
end |
function EEKarma:SendMassNotify(terget) |
_debug("SendMassNotify") |
if target~="guild" and target~="raid" then _debug("ÐевеÑÐ½Ð°Ñ ÑÐµÐ»Ñ Ð´Ð»Ñ Ð¼Ð°ÑÑ-оповеÑениÑ"); return false; end |
if target=="guild" then |
for i=1, GetNumGuildMembers(false) do |
local name, _, _, _, _, _, _, _, online, _, _ = GetGuildRosterInfo(i) |
if online then self:SendCommMessage("LSRA", "YOURKARMA;"..self:KarmaGetTotal(name), "WHISPER", name) end |
end |
elseif target=="raid" then |
if LSRaid:IsRaidActive() then |
for i=1, GetNumRaidMembers() do |
local name, _, _, _, _, _, _, online, _, _, _ = GetRaidRosterInfo(i) |
if online then self:SendCommMessage("LSRA", "YOURKARMA;"..self:KarmaGetTotal(name), "WHISPER", name) end |
end |
else |
_message("ÐÑ Ð½Ðµ в Ñейде.") |
end |
end |
end |
local function __________() |
-- ignore, IDE cheat |
end |
function EEKarma:DBCreate(name) |
return true |
end |
function EEKarma:DBUse(name) |
return true |
end |
function EEKarma:DBList() |
return true |
end |
function EEKarma:DBPrune(candidate) |
return true |
end |
function EEKarma:DBMigrate() |
return true |
end |
function EEKarma:DBCompact() |
return true |
end |
function EEKarma:DBActive() |
return true |
end |
local function __________() |
-- ignore, IDE cheat |
end |
function EEKarma:MassTarget_Select() |
_debug("MassTarget_Select") |
local ndb=this:GetID() |
UIDropDownMenu_SetSelectedID(self.MassTarget, ndb) |
SelectedMassTarget=ndb |
end |
function EEKarma:MassTarget_Initialize() |
_debug("MassTarget_Initialize") |
info = {} |
-- |
info.text = "Рейд" |
info.checked = 1 == SelectedMassTarget |
info.func = function() EEKarma:MassTarget_Select() end |
UIDropDownMenu_AddButton(info) |
-- |
info.text = "ÐилÑдиÑ" |
info.checked = 2 == SelectedMassTarget |
info.func = function() EEKarma:MassTarget_Select() end |
UIDropDownMenu_AddButton(info) |
end |
function EEKarma:CreateFrames() |
self.Anchor = CreateFrame("Frame", nil, UIParent) |
self.Anchor:SetScript("OnShow", function() EEKarma:OnShow() end ) |
self.Anchor:SetScript("OnHide", function() EEKarma:OnHide() end ) |
self.Anchor:SetFrameStrata("HIGH") |
local SingleKarmaLabel = self.Anchor:CreateFontString(nil,"ARTWORK","GameFontNormal") |
SingleKarmaLabel:SetText("ÐндивидÑалÑÐ½Ð°Ñ ÑаздаÑа") |
SingleKarmaLabel:SetPoint("TOPLEFT",self.Anchor,"TOPLEFT",30,-45) |
self.SingleKarma = CreateFrame("EditBox", "SingleKarma", self.Anchor, "InputBoxTemplate") |
self.SingleKarma:SetPoint("TOPLEFT", self.Anchor, "TOPLEFT", 30, -60) |
self.SingleKarma:SetWidth(40) |
self.SingleKarma:SetHeight(22) |
self.SingleKarma:SetAutoFocus(false) |
self.SingleKarma:ClearFocus() |
self.SingleMessage = CreateFrame("EditBox", "SingleMessage", self.Anchor, "InputBoxTemplate") |
self.SingleMessage:SetPoint("LEFT", self.SingleKarma, "RIGHT", 10, 0) |
self.SingleMessage:SetWidth(240) |
self.SingleMessage:SetHeight(22) |
self.SingleMessage:SetAutoFocus(false) |
self.SingleMessage:ClearFocus() |
self.ButtonSingleKarma = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") |
self.ButtonSingleKarma:SetHeight(26) |
self.ButtonSingleKarma:SetScript("OnClick", function() |
EEKarma:KarmaAdd(UnitName("target"), EEKarma.SingleKarma:GetText(), "3", EEKarma.SingleMessage:GetText()) |
EEKarma.SingleKarma:SetText("") |
EEKarma.SingleMessage:SetText("") |
end ) |
self.ButtonSingleKarma:SetPoint("LEFT", self.SingleMessage, "RIGHT", 20, 0) |
local MassKarmaLabel = self.Anchor:CreateFontString(nil,"ARTWORK","GameFontNormal") |
MassKarmaLabel:SetText("ÐаÑÑÐ¾Ð²Ð°Ñ ÑаздаÑа") |
MassKarmaLabel:SetPoint("TOPLEFT", self.Anchor, "TOPLEFT", 30, -105) |
self.MassKarma = CreateFrame("EditBox", "MassKarma", self.Anchor, "InputBoxTemplate") |
self.MassKarma:SetPoint("TOPLEFT", self.Anchor, "TOPLEFT", 30, -120) |
self.MassKarma:SetWidth(40) |
self.MassKarma:SetHeight(22) |
self.MassKarma:SetAutoFocus(false) |
self.MassKarma:ClearFocus() |
self.MassMessage = CreateFrame("EditBox", "MassMessage", self.Anchor, "InputBoxTemplate") |
self.MassMessage:SetPoint("LEFT", self.MassKarma, "RIGHT", 10, 0) |
self.MassMessage:SetWidth(240) |
self.MassMessage:SetHeight(22) |
self.MassMessage:SetAutoFocus(false) |
self.MassMessage:ClearFocus() |
self.MassTarget = CreateFrame("Button","MassTarget",self.Anchor,"UIDropDownMenuTemplate") |
self.MassTarget:SetScript("OnShow", function() |
UIDropDownMenu_Initialize(self.MassTarget, self.MassTarget_Initialize) |
UIDropDownMenu_SetSelectedID(self.MassTarget, SelectedMassTarget) |
UIDropDownMenu_SetWidth(self.MassTarget, 90) |
end ) |
self.MassTarget:SetPoint("LEFT", self.MassMessage, "RIGHT", -10, -3) |
self.ButtonMassKarma = CreateFrame("Button",nil,self.Anchor, "OptionsButtonTemplate") |
self.ButtonMassKarma:SetHeight(26) |
self.ButtonMassKarma:SetText("ÐÑдаÑÑ") |
self.ButtonMassKarma:SetScript("OnClick", function() |
-- TODO: magic numbers :/ |
if SelectedMassTarget == 1 then |
EEKarma:KarmaMassAdd("raid", EEKarma.MassKarma:GetText(), "3", EEKarma.MassMessage:GetText()) |
else |
EEKarma:KarmaMassAdd("guild", EEKarma.MassKarma:GetText(), "3", EEKarma.MassMessage:GetText()) |
end |
EEKarma.MassKarma:SetText("") |
EEKarma.MassMessage:SetText("") |
end ) |
self.ButtonMassKarma:SetPoint("LEFT", self.MassMessage, "RIGHT", 135, 0) |
-- self.KarmaStartRaid = CreateFrame("Button", nil, self.Anchor, "OptionsButtonTemplate") |
-- self.KarmaStartRaid:SetWidth(120) |
-- self.KarmaStartRaid:SetHeight(26) |
-- self.KarmaStartRaid:SetText("ÐаÑало Ñейда") |
-- self.KarmaStartRaid:SetScript("OnClick", function() |
-- EEKarma.MassKarma:SetText("2") |
-- EEKarma.MassMessage:SetText("ÐаÑма за наÑало Ñейда: "..GetRealZoneText()) |
-- end ) |
-- self.KarmaStartRaid:SetPoint("TOPLEFT", self.Anchor, "TOPLEFT", 20, -170) |
-- |
-- self.KarmaStopRaid = CreateFrame("Button", nil, self.Anchor, "OptionsButtonTemplate") |
-- self.KarmaStopRaid:SetWidth(120) |
-- self.KarmaStopRaid:SetHeight(26) |
-- self.KarmaStopRaid:SetText("ÐÐ¾Ð½ÐµÑ Ñейда") |
-- self.KarmaStopRaid:SetScript("OnClick", function() |
-- EEKarma.MassKarma:SetText("2") |
-- EEKarma.MassMessage:SetText("ÐаÑма за ÐºÐ¾Ð½ÐµÑ Ñейда") |
-- end ) |
-- self.KarmaStopRaid:SetPoint("TOPLEFT", self.KarmaStartRaid, "BOTTOMLEFT", 0, -5) |
end |
function EEKarma:OnShow() |
_debug("OnShow") |
end |
function EEKarma:OnHide() |
_debug("OnHide") |
end |
function EEKarma:OnInitialize() |
_debug("OnInitialize") |
--self.db = EERaidAdmin:GetDatabaseNamespace("EERaidAdminDB") |
self.db = LibStub("AceDB-3.0"):New("EERaidAdminDB") |
db = self.db.global |
self:DBUse(db['ActiveDB']) |
self:RegisterComm("LSRC") |
self:RegisterEvent("PLAYER_TARGET_CHANGED") |
-- self:RegisterEvent("RAID_ROSTER_UPDATE") |
-- self:RegisterEvent("LOOT_OPENED") |
-- self:RegisterEvent("LOOT_CLOSED") |
-- self:RegisterEvent("LOOT_SLOT_CLEARED") |
-- self:RegisterEvent("CHAT_MSG_SYSTEM") |
self:CreateFrames() |
self:PLAYER_TARGET_CHANGED() |
self.Anchor:Hide() |
end |
function EEKarma:OnCommReceived(prefix, message, distribution, sender) |
_debug("OnCommReceived") |
local tokens = { strsplit(";", message) } |
if prefix == "LSRC" then |
if tokens[1] == "GETKARMA" then |
local lootmethod, masterlooterPartyID, _ = GetLootMethod(); -- check if ML |
if lootmethod == "master" and masterlooterPartyID == 0 and EERaid:IsRaidActive() then |
self:SendCommMessage("LSRA", "YOURKARMA;"..self:KarmaGetTotal(sender), "WHISPER", sender) |
end |
end |
end |
end |
function EEKarma:OnEnable() |
_debug("OnEnable") |
end |
function EEKarma:OnDisable() |
_debug("OnDisable") |
end |
## Interface: 30300 |
## Title: EERaidAdmin |
## Notes: EasyEPGPAdmin for EPGP by Evl |
## Author: Ðвл, EU, ÐзÑÑÐµÐ³Ð¾Ñ |
## X-Author: ÐÑ , EU, ÐзÑÑÐµÐ³Ð¾Ñ |
## SavedVariables: EERaidAdminDB |
## X-Curse-Packaged-Version: v1.00.00 |
## X-Description: Easy EPGP Raid Admin provides an intuitive and easy to use interface for master-looters of guilds which are using EPGP loot distribution system. Please note: master looter should have original EPGP installed and activeted. |
libs\LibStub\LibStub.lua |
libs\CallbackHandler-1.0\CallbackHandler-1.0.lua |
libs\AceAddon-3.0\AceAddon-3.0.lua |
libs\AceConsole-3.0\AceConsole-3.0.lua |
libs\AceDB-3.0\AceDB-3.0.lua |
libs\AceLocale-3.0\AceLocale-3.0.lua |
libs\AceComm-3.0\ChatThrottleLib.lua |
libs\AceComm-3.0\AceComm-3.0.lua |
libs\AceBucket-3.0\AceBucket-3.0.lua |
libs\AceEvent-3.0\AceEvent-3.0.lua |
libs\AceTimer-3.0\AceTimer-3.0.lua |
libs\LibDebug-1.0\LibDebug-1.0.lua |
libs\LibGearPoints-1.0\LibGearPoints-1.0.lua |
locales\ruRU.lua |
EERaidAdmin.lua |
EELoot.lua |
EERaid.lua |
EEKarma.lua |
16459,478 |
------------------------------------------------------------------------ |
r49 | phantomee | 2009-10-16 11:29:40 +0000 (Fri, 16 Oct 2009) | 1 line |
Changed paths: |
A /tags/v0.98.85 (from /trunk:48) |
Tagging as v0.98.85 |
------------------------------------------------------------------------ |
r48 | phantomee | 2009-10-16 11:28:00 +0000 (Fri, 16 Oct 2009) | 1 line |
Changed paths: |
M /trunk/LSKarma.lua |
- oops |
------------------------------------------------------------------------ |
r47 | phantomee | 2009-10-16 11:20:47 +0000 (Fri, 16 Oct 2009) | 2 lines |
Changed paths: |
M /trunk/LSKarma.lua |
M /trunk/LSRaidAdmin.lua |
- minor typos |
- raid karma notification (not tested) |
------------------------------------------------------------------------ |
r46 | phantomee | 2009-10-16 10:25:18 +0000 (Fri, 16 Oct 2009) | 1 line |
Changed paths: |
M /trunk/LSRaid.lua |
- IsRaidActive fix |
------------------------------------------------------------------------ |
r44 | phantomee | 2009-10-14 22:59:57 +0000 (Wed, 14 Oct 2009) | 4 lines |
Changed paths: |
M /trunk/LSKarma.lua |
M /trunk/LSLoot.lua |
M /trunk/LSRaid.lua |
M /trunk/LSRaidAdmin.lua |
M /trunk/LSRaidAdmin.toc |
- Evl diff. |
- Karma autopacker on raidover |
- minor typos |
- version bump |
------------------------------------------------------------------------ |
EELoot = EERaidAdmin:NewModule("EELoot", "AceConsole-3.0", "AceBucket-3.0", "AceEvent-3.0", "AceComm-3.0") |
------ VARIABLES |
---- GLOBALS |
local db --= EERaidAdmin.db |
local __IsDebugging = 0 |
local __raidActiveGroups = EERaidAdmin.__raidActiveGroups |
local __raidActivePlayers = EERaidAdmin.__raidActivePlayers |
local ServerDateTime = EERaidAdmin.ServerDateTime |
--EELoot.db = db.global |
---- LOCALS |
local __UpdateRate = 0.1 |
local _WinnerRoll = 0 |
local _WinnerNames = {} |
local bars = {} |
local playerToBarIndex = {} |
local raidPlayers = {} |
local SelectedLoot = 1 |
local SelectedPlayer = nil |
local _LootMode |
local GP = LibStub("LibGearPoints-1.0"); |
-- Name cannot be the same as the object name, otherwise cannot be properly hooked :/ |
local RollLootTooltip = CreateFrame( "GameTooltip", "EELootGameTooltip", UIParent, "GameTooltipTemplate" ) |
------ HELPER FUNCTIONS |
local function _debug(msg, fatal) |
if __IsDebugging == 1 or fatal then |
EELoot:Print("|cffdd0000debug: "..msg.."|r") |
end |
end |
local function _color(r, g, b, msg) |
if type(r) == "table" then |
if r.r then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end |
end |
t_color = string.format("|cff%02x%02x%02x", r*255, g*255, b*255) |
if msg ~= '' then |
return t_color..msg..'|r' |
else |
return t_color |
end |
end |
local function _message(msg, label) |
local output = "" |
output = _color(0,1,1, 'EELoot: ') |
if label then |
output = output.._color(0,0.7,0.7, label..': ') |
end |
output = output..msg |
print(output) |
end |
local function _getItemId(itemlink) |
local prestring = string.gsub(itemlink, ".-\124H([^\124]*)\124h.*", "%1") |
local _,itemid,_,_,_,_,_,_,_ = strsplit(":", prestring) |
return itemid |
end |
local function _sortEligiblePlayers(a, b) |
if (not a) then |
return false |
elseif (not b) then |
return true |
else |
return (a.points > b.points) |
end |
end |
local function _sortRaidSubgroupAsc(a, b) |
if (not a) then |
return false |
elseif (not b) then |
return true |
else |
return (a.subgroup < b.subgroup) |
end |
end |
local function _adjustColorToIndex(index, r, g, b) |
local r, g, b = r, g, b |
if mod(index, 2) == 0 then |
-- |
else |
r = r+0.03 > 1 and r-0.03 or r+0.03 |
g = g+0.03 > 1 and g-0.03 or g+0.03 |
b = b+0.03 > 1 and b-0.03 or b+0.03 |
end |
return r, g, b |
end |
local function __________() |
-- ignore, IDE cheat |
end |
function EELoot:LOOT_OPENED() |
_debug("LOOT_OPENED") |
-- TODO: hotfix, otkryvaetsja toka v rejde, i toka MLom |
-- lootmethod, masterlooterPartyID, masterlooterRaidID = GetLootMethod(); |
-- if not(lootmethod == "master" and masterlooterPartyID == 0) then |
-- return; |
-- end |
if UnitInRaid("player") then |
-- FIXME: bruteforcing |
-- if revisiting, then skipping the checks |
for i = 1, GetNumLootItems() do |
if db.CollectedLoot[1] then -- esli sushestvuet pervyj podobranyj predmet... |
if LootSlotIsItem(i) then |
if db.CollectedLoot[1].itemLink == GetLootSlotLink(i) then -- FIXME: ...sravnivaem etot predmet s pervym iz podobranogo |
self:CollectLoot() |
EERaidAdmin.Anchor:Show() |
EERaidAdmin:SetTab(3) |
return |
end |
end |
end |
end |
-- ÐвÑоÑÐ±Ð¾Ñ Ð·ÐµÐ»ÐµÐ½ÐºÐ¸ |
if db.__AutoGreen == true then |
for i = 1, GetNumLootItems() do |
if LootSlotIsItem(i) then |
_, _, itemRarity, _, _, _, _, _, _, _ = GetItemInfo(GetLootSlotLink(i)) |
if itemRarity == 2 then |
-- najdena zelenka |
for ci = 1, GetNumRaidMembers() do |
-- otdaem sebe |
if (GetMasterLootCandidate(ci) == UnitName("player")) then |
_debug("ÐÑÑаÑÑÑ Ð¿Ð¾Ð´Ð¾Ð±ÑаÑÑ Ð·ÐµÐ»ÐµÐ½ÐºÑ",1) |
GiveMasterLoot(i, ci) |
end |
end |
end |
end |
end |
end |
-- else trying against ML threshold |
for i = 1, GetNumLootItems() do |
if LootSlotIsItem(i) then |
_, _, itemRarity, _, _, _, _, _, _, _ = GetItemInfo(GetLootSlotLink(i)) |
if itemRarity >= GetLootThreshold() and itemRarity ~= 2 then |
-- if itemRarity >= 0 then |
_debug("> rarity threshold met -- picking") |
self:CollectLoot() |
if db.__AutoAnnounceLoot == true then |
if (GetNumRaidMembers() > 20) then -- check if raid is large |
lootmethod, masterlooterPartyID, _ = GetLootMethod(); -- check if ML |
if (lootmethod == "master" and masterlooterPartyID == 0) then |
self:LootAnnounceGuild(); -- announce to guild |
end |
end |
end |
self:LootAnnounceRaid(); |
EERaidAdmin.Anchor:Show() |
EERaidAdmin:SetTab(3) |
return |
end |
end |
end |
end |
end |
function EELoot:LOOT_CLOSED() |
_debug("LOOT_CLOSED") |
self:OfflineMode() |
end |
function EELoot:LOOT_SLOT_CLEARED() |
_debug("LOOT_SLOT_CLEARED") |
if _LootMode == 1 then |
self:CollectLoot() |
self:CalculateWinner() |
self:DrawInterestAll() |
end |
end |
function EELoot:PLAYER_TARGET_CHANGED() |
-- if UnitExists("target") and UnitIsPlayer("target") then |
-- local _, class = UnitClass("target") |
-- self.GiveLoot:SetText("ÐÑдаÑÑ ".._hex(RAID_CLASS_COLORS[class])..UnitName("target").."|r") |
-- self.GiveLoot:Enable() |
-- else |
-- self.GiveLoot:SetText("ÐÑдаÑÑ |cffdd0000"..UnitName("target").."|r") |
-- self.GiveLoot:Disable() |
-- end |
-- local size = self.GiveLoot:GetTextWidth()+30 |
-- if size < 80 then |
-- size = 80 |
-- end |
-- |
-- self.GiveLoot:SetWidth(size) |
end |
function EELoot:RAID_ROSTER_UPDATE() |
_debug("RAID_ROSTER_UPDATE") |
if self.Anchor:IsVisible() then |
_debug("> anchor visible: updating") |
self:UpdateRaidPlayerInfo() |
self:DrawPlayerBars() |
self:CalculateWinner() |
self:DrawInterestAll() |
end |
end |
function EELoot:CHAT_MSG_SYSTEM() |
_debug("CHAT_MSG_SYSTEM") |
-- FIXME: move it down the ladder later |
if not db.CollectedLoot[SelectedLoot] then return end -- nothing to roll for |
if string.find(arg1, "вÑбÑаÑÑваеÑ") and string.find(arg1, "%(1%-100%)") then |
local _, _, name, roll = string.find(arg1, "(.+) вÑбÑаÑÑÐ²Ð°ÐµÑ (%d+)") -- TODO: any delocalized way to do this? |
self:CalculateRoll(name, roll) |
end |
end |
function EELoot:CHAT_MSG_SYSTEM_SLOW() |
_debug("CHAT_MSG_SYSTEM_SLOW") |
self:CalculateWinner() |
self:DrawInterestAll() |
end |
local function __________() |
-- ignore, IDE cheat |
end |
function EELoot:SendStartRoll() |
_debug("SendStartRoll") |
local t_eligible_players = self:GetEligiblePlayers() |
if #t_eligible_players > 0 then |
wipe(_WinnerNames) |
_WinnerRoll = 0 |
for i, name in ipairs(t_eligible_players) do |
db.CollectedLoot[SelectedLoot].interest[name].roll = 0 |
EELoot:SendCommMessage("LSRA", "START_ROLL", "WHISPER", name) |
end |
end |
end |
function EELoot:SendPollEquip(player) |
_debug("SendPollEquip") |
if not db.CollectedLoot[SelectedLoot] then return end |
local item = db.CollectedLoot[SelectedLoot].itemLink |
if not IsEquippableItem(item) then return end |
if player then |
_debug("> whisper") |
self:SendCommMessage("LSRA", "POLL_EQUIP;"..item, "WHISPER", player) |
else |
_debug("> raid") |
self:SendCommMessage("LSRA", "POLL_EQUIP;"..item, "RAID") |
end |
end |
function EELoot:SendRePoll(player) |
_debug("SendRePoll") |
if not db.CollectedLoot[SelectedLoot] then return end |
if not db.CollectedLoot[SelectedLoot].rolltype then return end |
self:DeleteInterest(player) |
wipe(_WinnerNames) |
_WinnerRoll = 0 |
self:DrawInterestAll() |
if db.CollectedLoot[SelectedLoot].rolltype == "STANDARD" then |
self:SendCommMessage("LSRA", "POLL_STANDARD;"..db.CollectedLoot[SelectedLoot].itemLink, "WHISPER", player) |
elseif db.CollectedLoot[SelectedLoot].rolltype == "QUICK" then |
self:SendCommMessage("LSRA", "POLL_QUICK;"..db.CollectedLoot[SelectedLoot].itemLink, "WHISPER", player) |
end |
end |
function EELoot:SendStandardRoll() |
_debug("SendStandardRoll") |
local item = db.CollectedLoot[SelectedLoot].itemLink |
self:DeleteInterest() |
self:ClearInterest() |
db.CollectedLoot[SelectedLoot].rolltype = "STANDARD" |
self:DrawInterestAll() |
self:SendPollEquip() |
self:SendCommMessage("LSRA", "POLL_STANDARD;"..item, "RAID") -- TODO: |
end |
function EELoot:SendQuickRoll() |
_debug("SendQuickRoll") |
local item = db.CollectedLoot[SelectedLoot].itemLink |
self:DeleteInterest() |
self:ClearInterest() |
db.CollectedLoot[SelectedLoot].rolltype = "QUICK" |
self:DrawInterestAll() |
self:SendPollEquip() |
self:SendCommMessage("LSRA", "POLL_QUICK;"..item, "RAID") -- TODO: |
end |
local function __________() |
-- ignore, IDE cheat |
end |
function EELoot:GetItemStatus(itemlink) |
_debug("GetItemStatus "..itemlink, 1) |
-- experemental tooltip parser |
local ScanTooltip = CreateFrame("GameTooltip", "ScanTooltip", UIParent, "GameTooltipTemplate") |
ScanTooltip:SetOwner(UIParent, "ANCHOR_NONE") |
ScanTooltip:ClearLines() |
ScanTooltip:SetHyperlink(itemlink) |
-- _debug(ScanTooltip:NumLines(), 1) |
if ScanTooltip:NumLines() > 3 then |
local bindstatus = getglobal("ScanTooltipTextLeft2"):GetText() |
local asd = getglobal("ScanTooltipTextRight2"):GetText() |
local asdf = getglobal("ScanTooltipTextLeft3"):GetText() |
local asdfg = getglobal("ScanTooltipTextRight3"):GetText() |
local r, g, b, a = getglobal("ScanTooltipTextRight2"):GetTextColor() |
print(bindstatus) |
print(asd) |
print(asdf) |
print(asdfg) |
print(r.." "..g.." "..b.." "..a) |
end |
ScanTooltip:Hide() |
end |
function EELoot:TestStatus() |
self:GetItemStatus(GetInventoryItemLink("player",1)) |
self:GetItemStatus(GetContainerItemLink(0, 1)) |
end |
function EELoot:UpdateRaidPlayerInfo() |
_debug("UpdateRaidPlayerInfo") |
-- wipe old tables |
wipe(raidPlayers) |
wipe(playerToBarIndex) |
for i = 1, GetNumRaidMembers(), 1 do |
local name, _, subgroup, _, _, class, _, online, _, _, _ = GetRaidRosterInfo(i) |
raidPlayers[i] = { name=name, class=class, subgroup=subgroup, online = online } |
end |
-- sort, according to the subgroup number (1,2..) |
table.sort(raidPlayers, _sortRaidSubgroupAsc) |
-- fill the playerToBarIndex lookup table |
for i, v in pairs(raidPlayers) do |
playerToBarIndex[v.name] = i |
end |
end |
function EELoot:DrawPlayerBars() |
_debug("DrawPlayerBars") |
-- Hide all bars |
for i = 0, #bars do |
bars[i]:Hide() |
end |
-- clean them out |
wipe(bars) |
-- recreate the bars from scratch |
for i = 1, #raidPlayers, 1 do |
local name, class, subgroup, online = raidPlayers[i].name, raidPlayers[i].class, raidPlayers[i].subgroup, raidPlayers[i].online |
if subgroup <= 5 then -- TODO: strogo 5 pervyh grupp? |
-- set player name and class color, paint gray if user is offline |
bars[i].PlayerNameText:SetText(name) |
bars[i].player = name |
bars[i].class = class |
if online then |
bars[i].PlayerNameText:SetTextColor(RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b, 1) |
else |
bars[i].PlayerNameText:SetTextColor(0.4, 0.4,0.4) |
end |
bars[i].Karma:SetText('|cffe6cc80'..EEKarma:KarmaGetTotal(name)..'|r') |
-- show the bar |
bars[i].ItemText:Hide() |
bars[i]:Show() |
end |
-- limit the number of bars |
if i == __raidActivePlayers then break end |
end |
end |
function EELoot:SelectPlayer(bar_id) |
_debug("SelectPlayer") |
if not db.CollectedLoot[SelectedLoot] then return end |
if db.CollectedLoot[SelectedLoot].winner then |
-- TODO: esli pobeditel' uzhe ustanovlen, sootvetstvenno zabrana karma, |
-- to s vydelennym chelovekom bol'she nichego podelat' nel'zja, tak li eto? |
else |
self:DrawInterestAll() |
-- highlight the bar |
SelectedPlayer = bar_id |
local i_r, i_g, i_b = _adjustColorToIndex(bar_id, 0.50, 0.50, 0) |
bars[bar_id].texture:SetTexture(i_r,i_g,i_b,0.95) |
bars[bar_id]:SetBackdropColor(0,0,0,0) |
-- set "declare winner" button and its "deduct karma" window |
self.WinnerButton:SetText("ÐÑигÑал ".._color(RAID_CLASS_COLORS[bars[bar_id].class], nil, nil, bars[bar_id].player)) |
local size = self.WinnerButton:GetTextWidth()+30 |
if size < 80 then size = 80; end |
self.WinnerButton:SetWidth(size) |
self.WinnerButton:Enable(); |
self.DeductKarma:SetText(self:GetKarmaCost(bars[bar_id].player)) |
-- give loot button |
-- self.GiveLootButton:SetText("ÐÑдаÑÑ ".._color(RAID_CLASS_COLORS[bars[bar_id].class], nil, nil, bars[bar_id].player)) |
-- local size = self.GiveLootButton:GetTextWidth()+30 |
-- if size < 80 then size = 80; end |
-- self.GiveLootButton:SetWidth(size) |
-- if _LootMode == 1 then self.GiveLootButton:Enable() end |
end |
end |
function EELoot:DenyPlayer(bar_id) |
_debug("DenyPlayer") |
if db.CollectedLoot[SelectedLoot] then |
_debug(">") |
if db.CollectedLoot[SelectedLoot].interest then |
_debug(">>") |
if db.CollectedLoot[SelectedLoot].interest[bars[bar_id].player] then |
_debug(">>>") |
self:DeleteInterest(bars[bar_id].player) |
db.CollectedLoot[SelectedLoot].interest[bars[bar_id].player].interest = "PASS" |
self:CalculateWinner() |
self:DrawInterestAll() |
end |
end |
end |
end |
local function ______bars() |
--vvvvvvvvvvvvvvvvvvv |
end |
setmetatable(bars, {__index = function(self, bar_id) |
-- refactor local options |
local inset = 20 |
local height = 20 |
local fontsize = 13 |
local bar = CreateFrame("Button", nil, EELoot.BarList) |
self[bar_id] = bar |
bar.player = nil |
bar.class = nil |
--bar:SetWidth(EELoot.BarList:GetWidth()) |
bar:SetHeight(height) |
bar:EnableMouse(true) |
bar:SetFrameStrata("HIGH") |
bar:RegisterForClicks("LeftButtonUp", "RightButtonUp") |
bar:SetHighlightTexture( "Interface\\QuestFrame\\UI-QuestTitleHighlight") |
bar:SetPoint("TOPLEFT", EELoot.BarList, "TOPLEFT", 0, -((bar_id-1) * height) ) |
bar:SetPoint("TOPRIGHT", EELoot.BarList, "TOPRIGHT", 0, -((bar_id-1) * height) ) |
-- paint the bar with solid texture, and a striped backdrop for alternate effect |
bar.texture = bar:CreateTexture() |
bar.texture:SetAllPoints(bar) |
local i_r, i_g, i_b = _adjustColorToIndex(bar_id, 0.25, 0.25, 0.25) |
bar.texture:SetTexture(i_r, i_g, i_b, 0.5) |
bar:SetBackdrop( {bgFile = "Interface\\Addons\\EERaidAdmin\\textures\\Stripes", edgeFile = nil, tile = true, tileSize = 32, edgeSize = nil, insets = { left = 0, right = 0, top = 0, bottom = 0 }}); |
bar:SetBackdropColor(i_r, i_g, i_b, 0.0) |
bar:SetScript("OnClick", function(self, button) |
if button == "LeftButton" then |
EELoot:SelectPlayer(bar_id) |
elseif button == "RightButton" then |
EELoot:DenyPlayer(bar_id) |
end |
end) |
bar.PlayerNameText = bar:CreateFontString(nil, nil, "GameFontNormalSmall") |
bar.PlayerNameText:SetFont("Fonts\\FRIZQT__.TTF", fontsize) |
bar.PlayerNameText:SetJustifyH("LEFT") |
bar.PlayerNameText:SetWidth(80) |
bar.PlayerNameText:SetHeight(fontsize) |
bar.PlayerNameText:SetNonSpaceWrap(false) |
bar.PlayerNameText:SetPoint("LEFT", bar, "LEFT", 10, 0) |
bar.ItemText = CreateFrame("Button", nil, bar) |
local t_f_s1 = bar.ItemText:CreateFontString(nil, nil, "GameFontNormalSmall") |
t_f_s1:SetFont("Fonts\\FRIZQT__.TTF", fontsize-1) |
t_f_s1:SetJustifyH("LEFT") |
t_f_s1:SetPoint("LEFT") |
t_f_s1:SetWidth(300) |
t_f_s1:SetNonSpaceWrap(false) |
bar.ItemText:SetFontString(t_f_s1) |
bar.ItemText:EnableMouse(true) |
bar.ItemText:SetWidth(300) |
bar.ItemText:SetHeight(height) |
bar.ItemText:SetPoint("LEFT", bar.PlayerNameText, "RIGHT", 5, 0) |
bar.ItemText:SetScript("OnClick", function() |
EELoot:SendPollEquip(bar.PlayerNameText:GetText()) |
end ) |
bar.ItemText:SetScript("OnEnter", function() |
if bar.ItemText:GetText() then |
if GetItemInfo(bar.ItemText:GetText()) then |
RollLootTooltip:SetOwner(bar.ItemText, "ANCHOR_BOTTOMRIGHT", -(bar.ItemText:GetWidth()+5), 0) |
RollLootTooltip:ClearAllPoints(); |
RollLootTooltip:SetHyperlink(bar.ItemText:GetText()) |
RollLootTooltip:Show() |
end |
end |
end) |
bar.ItemText:SetScript("OnLeave", function() |
RollLootTooltip:Hide(); |
end) |
bar.ItemText:Hide() |
bar.Total = bar:CreateFontString(nil, nil, "GameFontNormalSmall") |
bar.Total:SetFont("Fonts\\FRIZQT__.TTF", fontsize) |
bar.Total:SetJustifyH("LEFT") |
bar.Total:SetWidth(35) -- TODO: |
bar.Total:SetHeight(fontsize) -- TODO: |
bar.Total:SetNonSpaceWrap(false) |
bar.Total:SetPoint("RIGHT", bar, "RIGHT") |
bar.Roll = bar:CreateFontString(nil, nil, "GameFontNormalSmall") |
bar.Roll:SetFont("Fonts\\FRIZQT__.TTF", fontsize) |
bar.Roll:SetJustifyH("LEFT") |
bar.Roll:SetWidth(35) |
bar.Roll:SetHeight(fontsize) |
bar.Roll:SetNonSpaceWrap(false) |
bar.Roll:SetPoint("RIGHT", bar.Total, "LEFT", -10, 0) |
bar.Karma = bar:CreateFontString(nil, nil, "GameFontNormalSmall") |
bar.Karma:SetFont("Fonts\\FRIZQT__.TTF", fontsize) |
bar.Karma:SetJustifyH("RIGHT") |
bar.Karma:SetWidth(35) |
bar.Karma:SetHeight(fontsize) |
bar.Karma:SetNonSpaceWrap(false) |
bar.Karma:SetPoint("RIGHT", bar.Roll, "LEFT", -5, 0) |
bar.InterestPane = CreateFrame("Frame",nil,bar) |
--bar.InterestPane:EnableMouse(true) |
bar.InterestPane:SetFrameStrata("DIALOG") |
bar.InterestPane:SetWidth(30) |
bar.InterestPane:SetHeight(height) |
bar.InterestPane:SetPoint("RIGHT", bar.Karma, "LEFT", 0, 0) |
-- paint the bar with solid texture, and a striped backdrop for alternate effect |
bar.InterestPane.texture = bar.InterestPane:CreateTexture() |
--bar.InterestPane.texture:SetDrawLayer("OVERLAY") |
bar.InterestPane.texture:SetPoint("CENTER") |
bar.InterestPane.texture:SetAllPoints(bar.InterestPane) |
bar.texture:SetTexture(0, 0, 0, 0) |
bar.InterestPane:SetBackdrop( {bgFile = "Interface\\Addons\\EERaidAdmin\\textures\\Stripes", edgeFile = nil, tile = true, tileSize = 32, edgeSize = nil, insets = { left = 0, right = 0, top = 0, bottom = 0 }}); |
bar.InterestPane:SetBackdropColor(0, 0, 0, 0) |
bar.InterestButton = CreateFrame("Button", nil, bar.InterestPane) |
local t_f_s2 = bar.InterestButton:CreateFontString(nil, nil, "GameFontNormalSmall") |
t_f_s2:SetFont("Fonts\\FRIZQT__.TTF", fontsize+2) |
t_f_s2:SetJustifyH("CENTER") |
t_f_s2:SetPoint("CENTER") |
bar.InterestButton:SetFontString(t_f_s2) |
bar.InterestButton:EnableMouse(true) |
bar.InterestButton:SetHeight(16) |
bar.InterestButton:SetWidth(16) |
bar.InterestButton:SetScript("OnClick", function() EELoot:SendRePoll(bar.player) end ) |
bar.InterestButton:SetPoint("CENTER", bar.InterestPane, 0, 0) |
return bar |
end}) |
function EELoot:GetKarmaCost(player) |
_debug("GetKarmaCost") |
if not db.CollectedLoot[SelectedLoot] then return 0 end |
if not db.CollectedLoot[SelectedLoot].interest then return 0 end |
if not db.CollectedLoot[SelectedLoot].interest[player] then return 0 end |
if not db.CollectedLoot[SelectedLoot].interest[player].interest then return 0 end |
if db.CollectedLoot[SelectedLoot].interest[player].interest == "NEEDMAIN" or db.CollectedLoot[SelectedLoot].interest[player].interest == "NEEDOFF" then |
-- return floor(EEKarma:KarmaGetTotal(player)/2); |
-- _debug("SL"..(db.CollectedLoot[SelectedLoot].itemLink), 1) |
local gp1, gp2, ilvl = GP:GetValue(db.CollectedLoot[SelectedLoot].itemLink) |
return gp1; |
else |
return 0 |
end |
end |
function EELoot:GetEligiblePlayers() |
_debug("GetEligiblePlayers") |
if not db.CollectedLoot[SelectedLoot] then return {} end |
if not db.CollectedLoot[SelectedLoot].interest then return {} end |
---- sort player interest into three tiers |
-- FIXME: brutal but transparent, refactor later |
local tier1 = {} |
local tier2 = {} |
local tier3 = {} |
for name, interest in pairs(db.CollectedLoot[SelectedLoot].interest) do |
if playerToBarIndex[name] then |
if interest['interest'] == "NEEDMAIN" then |
tinsert(tier1, {name=name, points=EEKarma:KarmaGetTotal(name)}) |
elseif interest['interest'] == "NEEDOFF" then |
tinsert(tier2, {name=name, points=EEKarma:KarmaGetTotal(name)}) |
elseif interest['interest'] == "GREEDMAIN" then |
tinsert(tier3, {name=name, points=0}) |
elseif interest['interest'] == "GREEDOFF" then |
tinsert(tier3, {name=name, points=0}) |
end |
end |
end |
---- pick a tier |
local r_tier = {} |
if #tier1 > 0 then |
r_tier = tier1 |
elseif #tier2 > 0 then |
r_tier = tier2 |
elseif #tier3 > 0 then |
r_tier = tier3 |
else -- otherwise return an empty table |
return {} |
end |
-- filter 3 and return |
local r_names = {} |
table.sort(r_tier, _sortEligiblePlayers) |
for i, v in ipairs(r_tier) do |
if i > 1 then |
if r_tier[1].points - v.points > 3 then |
break |
else |
tinsert(r_names, v.name) |
end |
else |
tinsert(r_names, v.name) |
end |
end |
return r_names |
end |
function EELoot:DeclareWinner() |
_debug("DeclareWinner") |
if not db.CollectedLoot[SelectedLoot] then return end |
if db.CollectedLoot[SelectedLoot].winner then return end |
-- determine pretendent |
local pretendent |
if SelectedPlayer then |
pretendent = bars[SelectedPlayer].player |
else |
pretendent = _WinnerNames[1] |
end |
---- deduct karma if aplicable |
-- prevalidate entered karma |
local t_karma = self.DeductKarma:GetText() |
if not string.find(t_karma, "^%s*[+-]*[%d]+%s*$") then _debug("> каÑма должна бÑÑÑ ÑиÑлом", 1); return end |
t_karma = (abs(tonumber(t_karma))) |
-- set winner |
db.CollectedLoot[SelectedLoot].winner = pretendent |
local interestTable = {}; |
interestTable['NEEDMAIN'] = 1; |
interestTable['NEEDOFF'] = 2; |
-- pay karma |
local interest = interestTable[db.CollectedLoot[SelectedLoot].interest[pretendent]['interest']]; |
if (not interest) then |
interest = 0; |
end; |
-- _debug(">interest is "..interest, 1); |
EEKarma:KarmaAdd(pretendent, t_karma, interest, db.CollectedLoot[SelectedLoot].itemLink) |
-- notify winner |
self:SendCommMessage("LSRA", "WINNER;"..pretendent..", "..db.CollectedLoot[SelectedLoot].itemLink, "RAID") |
self:CalculateWinner() |
self:DrawInterestAll() |
end |
function EELoot:CalculateWinner() |
_debug("CalculateWinner") |
wipe(_WinnerNames) |
_WinnerRoll = 0 |
SelectedPlayer = nil |
if not db.CollectedLoot[SelectedLoot] then return end |
if not db.CollectedLoot[SelectedLoot].winner then -- esli pobeditel' uzhe ne opredelen |
if not db.CollectedLoot[SelectedLoot].interest then return end |
-- calculate actual winner |
for player, interest in pairs(db.CollectedLoot[SelectedLoot].interest) do |
if interest.totalroll then |
if interest.totalroll > _WinnerRoll then |
_debug(">> new winner "..interest.totalroll.." ".._WinnerRoll.." "..player) |
-- risovat' igroka |
_WinnerRoll = interest.totalroll |
wipe(_WinnerNames) |
tinsert(_WinnerNames, player) |
-- |
elseif interest.totalroll == _WinnerRoll then |
_debug(">> new tie "..interest.totalroll.." ".._WinnerRoll.." "..player) |
tinsert(_WinnerNames, player) |
end |
end |
end |
if #_WinnerNames == 1 then |
self.WinnerButton:SetText("ÐÑигÑал ".._WinnerNames[1]) |
local size = self.WinnerButton:GetTextWidth()+30 |
if size < 80 then size = 80; end |
self.WinnerButton:SetWidth(size) |
self.WinnerButton:Enable() |
self.DeductKarma:SetText(self:GetKarmaCost(_WinnerNames[1])) |
-- |
self.GiveLootButton:SetText("ÐÐµÐºÐ¾Ð¼Ñ Ð²ÑдаÑÑ") |
local size = self.GiveLootButton:GetTextWidth()+30 |
if size < 80 then size = 80; end |
self.GiveLootButton:SetWidth(size) |
self.GiveLootButton:Disable() |
else |
-- ne opredelen pobeditel' |
self.WinnerButton:SetText("ÐобедиÑÐµÐ»Ñ Ð½Ðµ опÑеделен") |
local size = self.WinnerButton:GetTextWidth()+30 |
if size < 80 then size = 80; end |
self.WinnerButton:SetWidth(size) |
self.WinnerButton:Disable() |
self.DeductKarma:SetText('') |
-- |
self.GiveLootButton:SetText("ÐÐµÐºÐ¾Ð¼Ñ Ð²ÑдаÑÑ") |
local size = self.GiveLootButton:GetTextWidth()+30 |
if size < 80 then size = 80; end |
self.GiveLootButton:SetWidth(size) |
self.GiveLootButton:Disable() |
end |
else |
-- esli pobeditel' opredelen, vkljuchit' knopku vydachi, i zadiejblit' knopku opredelenija pobeditelja |
self.WinnerButton:SetText("ÐÑигÑал "..db.CollectedLoot[SelectedLoot].winner) |
local size = self.WinnerButton:GetTextWidth()+30 |
if size < 80 then size = 80; end |
self.WinnerButton:SetWidth(size) |
self.WinnerButton:Disable() |
self.DeductKarma:SetText('') |
-- |
self.GiveLootButton:SetText("ÐÑдаÑÑ "..db.CollectedLoot[SelectedLoot].winner) |
local size = self.GiveLootButton:GetTextWidth()+30 |
if size < 80 then size = 80; end |
self.GiveLootButton:SetWidth(size) |
if _LootMode == 1 then self.GiveLootButton:Enable() end |
end |
end |
function EELoot:CalculateRoll(name, roll) |
if not db.CollectedLoot[SelectedLoot].interest then return end -- premature roll, item not defined |
if not db.CollectedLoot[SelectedLoot].interest[name] then return end -- not allowed to roll, did not declare interest |
if not db.CollectedLoot[SelectedLoot].interest[name].roll then return end -- roll = 0 mustbe preset to allow roll |
if db.CollectedLoot[SelectedLoot].interest[name].roll == 0 then -- if havent already rolled |
-- set and display roll ammount |
db.CollectedLoot[SelectedLoot].interest[name].roll = tonumber(roll) |
bars[playerToBarIndex[name]].Roll:SetText('+|cffffff00'..roll..'|r') |
-- calculate total with all respects |
local total |
-- needs use karma with their roll |
if db.CollectedLoot[SelectedLoot].interest[name].interest == "NEEDMAIN" or db.CollectedLoot[SelectedLoot].interest[name].interest == "NEEDOFF" then |
_debug(">>b "..db.CollectedLoot[SelectedLoot].interest[name].interest) |
total = roll + EEKarma:KarmaGetTotal(name) |
-- greeds do not use karma with their roll |
else |
_debug(">>nb "..db.CollectedLoot[SelectedLoot].interest[name].interest) |
total = roll |
end |
db.CollectedLoot[SelectedLoot].interest[name].totalroll = tonumber(total) |
bars[playerToBarIndex[name]].Total:SetText('|cffffffff'..total..'|r') |
end |
end |
function EELoot:GiveLoot() |
_debug("GiveLoot") |
if not db.CollectedLoot[SelectedLoot].winner then _debug("ÐекоÑÑекÑÐ½Ð°Ñ Ð¿Ð¾Ð¿ÑÑка вÑдаÑÑ Ð½Ðµ победиÑелÑ" ,1); return end |
local pretendent = db.CollectedLoot[SelectedLoot].winner |
_debug("попÑÑка вÑдаÑÑ "..db.CollectedLoot[SelectedLoot].itemLink..", "..pretendent) |
for ci = 1, GetNumRaidMembers() do |
if (GetMasterLootCandidate(ci) == pretendent ) then |
for li = 1, GetNumLootItems() do |
if LootSlotIsItem(li) then |
if GetLootSlotLink(li) == db.CollectedLoot[SelectedLoot].itemLink then |
_message(GetLootSlotLink(li)..", "..pretendent, "ÐÑÑаÑÑÑ Ð²ÑдаÑÑ") |
GiveMasterLoot(li, ci) |
return true |
end |
end |
end |
end |
end |
_debug("Ðе полÑÑилоÑÑ Ð²ÑдаÑÑ "..db.CollectedLoot[SelectedLoot].itemLink..", "..pretendent, 1) |
return false |
end |
function EELoot:LootAnnounceRaid() |
-- local linkstext = '' |
if #db.CollectedLoot > 0 then |
for i = 1, #db.CollectedLoot do |
-- local iteminfo = db.CollectedLoot[i].itemLink |
-- -- silly |
-- if linkstext == '' then |
-- linkstext = iteminfo |
-- else |
-- linkstext = linkstext..' '..iteminfo |
-- end |
self:SendCommMessage("LSRA", "ANNOUNCE_LOOT;"..db.CollectedLoot[i].itemLink, "RAID") |
end |
-- self:SendCommMessage("LSRA", "ANNOUNCE_LOOT;"..linkstext, "RAID") |
end |
end |
function EELoot:LootAnnounceGuild() |
-- local linkstext = '' |
if db.CollectedLoot.loottarget ~= "" then |
ChatThrottleLib:SendChatMessage("NORMAL", "LSRA", "ÐÑÑ: "..db.CollectedLoot.loottarget, "GUILD") |
else |
ChatThrottleLib:SendChatMessage("NORMAL", "LSRA", "ÐÑÑ: ÑÑндÑк", "GUILD") |
end |
if #db.CollectedLoot > 0 then |
for i = 1, #db.CollectedLoot do |
ChatThrottleLib:SendChatMessage("NORMAL", "LSRA", db.CollectedLoot[i].itemLink, "GUILD") |
end |
end |
end |
function EELoot:OnlineMode() |
_debug("OnlineMode") |
_LootMode = 1 |
self.LootStatus:SetBackdropColor(0.2,0.7,0.2,0.5) |
-- |
if not db.CollectedLoot.loottarget then |
if UnitIsDead("target") and UnitIsEnemy("player", "target") and not UnitIsPlayer("unit") then |
db.CollectedLoot.loottarget = UnitName("target") |
else |
db.CollectedLoot.loottarget = "Custom Loot" |
end |
end |
-- |
self.LootTargetName:SetText(db.CollectedLoot.loottarget) |
self:DrawPlayerBars() |
self:CalculateWinner() |
self:DrawInterestAll() |
end |
function EELoot:OfflineMode() |
_debug("OfflineMode") |
_LootMode = 2 |
self.GiveLootButton:Disable() |
self.LootStatus:SetBackdropColor(0.7,0.2,0.2,0.5) |
end |
function EELoot:CollectLoot() |
_debug("CollectLoot") |
-- smotrim est' li chto sobrat' |
local t_collecteditems = {} |
for i = 1, GetNumLootItems() do |
if LootSlotIsItem(i) then |
tinsert(t_collecteditems,{itemLink=GetLootSlotLink(i)}) |
end |
end |
-- esli chto-to podobrali |
if #t_collecteditems > 0 then |
for i, v in ipairs(t_collecteditems) do |
for ti, tv in ipairs(db.CollectedLoot) do |
if v.itemLink == tv.itemLink then |
t_collecteditems[i].interest = db.CollectedLoot[ti].interest |
t_collecteditems[i].winner = db.CollectedLoot[ti].winner |
t_collecteditems[i].rolltype = db.CollectedLoot[ti].rolltype |
break |
end |
end |
end |
wipe(db.CollectedLoot) |
db.CollectedLoot = t_collecteditems |
UIDropDownMenu_Initialize(self.LootDropDownMenu, self.LootDropDownMenu_Initialize) |
SelectedLoot = 1 |
UIDropDownMenu_SetSelectedID(self.LootDropDownMenu, 1) |
-- |
self.StandardRoll:Enable() |
self.QuickRoll:Enable() |
self:OnlineMode() |
return #db.CollectedLoot |
else |
-- pusto, zametaem sledy |
wipe(db.CollectedLoot) |
-- |
UIDropDownMenu_Initialize(self.LootDropDownMenu, self.LootDropDownMenu_Initialize) |
SelectedLoot = 1 |
UIDropDownMenu_SetSelectedID(self.LootDropDownMenu, 1) |
-- |
self:DeleteInterest() |
self:ClearInterest() |
self:OfflineMode() |
self.StandardRoll:Disable() |
self.QuickRoll:Disable() |
self.ButtonStartRoll:Disable() |
EERaidAdmin.Anchor:Hide() |
return 0 |
end |
end |
function EELoot:ManualCollectLoot(lootLink) |
_debug("ManualCollectLoot") |
-- add custom item to roll list |
local t_collecteditems = {} |
tinsert(t_collecteditems,{itemLink=lootLink}) |
-- esli chto-to podobrali |
if #t_collecteditems > 0 then |
for i, v in ipairs(t_collecteditems) do |
for ti, tv in ipairs(db.CollectedLoot) do |
if v.itemLink == tv.itemLink then |
t_collecteditems[i].interest = db.CollectedLoot[ti].interest |
t_collecteditems[i].winner = db.CollectedLoot[ti].winner |
t_collecteditems[i].rolltype = db.CollectedLoot[ti].rolltype |
break |
end |
end |
end |
wipe(db.CollectedLoot) |
db.CollectedLoot = t_collecteditems |
UIDropDownMenu_Initialize(self.LootDropDownMenu, self.LootDropDownMenu_Initialize) |
SelectedLoot = 1 |
UIDropDownMenu_SetSelectedID(self.LootDropDownMenu, 1) |
-- |
self.StandardRoll:Enable() |
self.QuickRoll:Enable() |
self:OnlineMode() |
return #db.CollectedLoot |
else |
-- pusto, zametaem sledy |
wipe(db.CollectedLoot) |
-- |
UIDropDownMenu_Initialize(self.LootDropDownMenu, self.LootDropDownMenu_Initialize) |
SelectedLoot = 1 |
UIDropDownMenu_SetSelectedID(self.LootDropDownMenu, 1) |
-- |
self:DeleteInterest() |
self:ClearInterest() |
self:OfflineMode() |
self.StandardRoll:Disable() |
self.QuickRoll:Disable() |
self.ButtonStartRoll:Disable() |
EERaidAdmin.Anchor:Hide() |
return 0 |
end |
end |
function EELoot:DeleteInterest(player) |
_debug("DeleteInterest") |
if not db.CollectedLoot[SelectedLoot] then return end |
if not db.CollectedLoot[SelectedLoot].interest then return end |
if player then |
if not db.CollectedLoot[SelectedLoot].interest[player] then return end |
wipe(db.CollectedLoot[SelectedLoot].interest[player]) |
else |
wipe(db.CollectedLoot[SelectedLoot].interest) |
db.CollectedLoot[SelectedLoot].winner = nil |
end |
end |
function EELoot:ClearInterest() |
for i = 1, #bars, 1 do |
local i_r, i_g, i_b = _adjustColorToIndex(i, 0.25, 0.25, 0.25) |
bars[i].InterestPane.texture:SetTexture(0, 0, 0, 0) |
bars[i].InterestPane:SetBackdropColor(0, 0, 0, 0) |
bars[i].InterestButton:SetNormalTexture(nil) |
bars[i].InterestButton:SetText('') |
bars[i].texture:SetTexture(i_r, i_g, i_b, 0.5) |
bars[i]:SetBackdropColor(i_r, i_g, i_b, 0) |
bars[i].Roll:SetText('') |
bars[i].Total:SetText('') |
end |
end |
function EELoot:DrawInterest(player) |
_debug("DrawInterest: "..player) |
if self.Anchor:IsVisible() then |
-- valid bar check |
if not bars then return end |
if not playerToBarIndex[player] then return end |
if not (playerToBarIndex[player] <= __raidActivePlayers) then return end |
if not db.CollectedLoot[SelectedLoot].winner then |
if not db.CollectedLoot[SelectedLoot].rolltype then |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(0,0,0,0) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(0,0,0,0) |
bars[playerToBarIndex[player]].InterestButton:SetText('') |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture(nil) |
return |
else |
if not db.CollectedLoot[SelectedLoot].interest then |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(0,0,0,0) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(0,0,0,0) |
bars[playerToBarIndex[player]].InterestButton:SetText('?') |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture(nil) |
return |
else |
if not db.CollectedLoot[SelectedLoot].interest[player] then |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(0,0,0,0) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(0,0,0,0) |
bars[playerToBarIndex[player]].InterestButton:SetText('?') |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture(nil) |
return |
end |
end |
end |
end |
if not db.CollectedLoot[SelectedLoot].interest then return end |
if not db.CollectedLoot[SelectedLoot].interest[player] then return end |
if db.CollectedLoot[SelectedLoot].interest[player].roll then |
local roll = db.CollectedLoot[SelectedLoot].interest[player].roll |
bars[playerToBarIndex[player]].Roll:SetText('+|cffffff00'..roll..'|r') |
local totalroll = db.CollectedLoot[SelectedLoot].interest[player].totalroll |
bars[playerToBarIndex[player]].Total:SetText('|cffffffff'..totalroll..'|r') |
end |
-- if db.CollectedLoot[SelectedLoot].interest[player].currentitem then |
-- bars[playerToBarIndex[player]].ItemText:SetText(db.CollectedLoot[SelectedLoot].interest[player].currentitem) |
-- bars[playerToBarIndex[player]].ItemText:Show() |
-- end |
if not db.CollectedLoot[SelectedLoot].winner then |
-- poshli vse proverki - podbiraem interes igroka |
local t_interest = db.CollectedLoot[SelectedLoot].interest[player]['interest'] |
-- TODO: brutforsim :) |
if t_interest == "NEEDMAIN" then |
_debug("NEEDMAIN") |
--local i_r, i_g, i_b = _adjustColorToIndex(playerToBarIndex[player], 0.40, 0.10, 0.40) |
local i_r, i_g, i_b = 0.60, 0.10, 0.60 |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(i_r,i_g,i_b,1) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(0,0,0,0) |
bars[playerToBarIndex[player]].InterestButton:SetText("1N") |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture(nil) |
elseif t_interest == "GREEDMAIN" then |
_debug("GREEDMAIN") |
--local i_r, i_g, i_b = _adjustColorToIndex(playerToBarIndex[player], 0.40, 0.10, 0.40) |
local i_r, i_g, i_b = 0.60, 0.10, 0.60 |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(0,0,0,0) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(i_r,i_g,i_b,1) |
bars[playerToBarIndex[player]].InterestButton:SetText("1G") |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture(nil) |
elseif t_interest == "NEEDOFF" then |
_debug("NEEDOFF") |
--local i_r, i_g, i_b = _adjustColorToIndex(playerToBarIndex[player], 0.10, 0.10, 0.50) |
local i_r, i_g, i_b = 0.10, 0.10, 0.60 |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(i_r,i_g,i_b,1) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(0,0,0,0) |
bars[playerToBarIndex[player]].InterestButton:SetText("2N") |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture(nil) |
elseif t_interest == "GREEDOFF" then |
_debug("GREEDOFF") |
--local i_r, i_g, i_b = _adjustColorToIndex(playerToBarIndex[player], 0.10, 0.10, 0.50) |
local i_r, i_g, i_b = 0.10, 0.10, 0.60 |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(0,0,0,0) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(i_r,i_g,i_b,1) |
bars[playerToBarIndex[player]].InterestButton:SetText("2G") |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture(nil) |
elseif t_interest == "PASS" then |
_debug("PASS") |
--local i_r, i_g, i_b = _adjustColorToIndex(playerToBarIndex[player], 0.25, 0.25, 0.25) |
local i_r, i_g, i_b = 0.40, 0.40, 0.40 |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(0,0,0,0) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(i_r,i_g,i_b,1) |
bars[playerToBarIndex[player]].InterestButton:SetText('P') |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture(nil) |
elseif t_interest == "TIMEOUT" then |
_debug("TIMEOUT") |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(0,0,0,0) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(0,0,0,0) |
bars[playerToBarIndex[player]].InterestButton:SetText('') |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture("Interface\\Addons\\EERaidAdmin\\textures\\Time") |
elseif t_interest == "NA" then |
_debug("NA") |
bars[playerToBarIndex[player]].InterestPane.texture:SetTexture(0,0,0,0) |
bars[playerToBarIndex[player]].InterestPane:SetBackdropColor(0,0,0,0) |
bars[playerToBarIndex[player]].InterestButton:SetText('') |
bars[playerToBarIndex[player]].InterestButton:SetNormalTexture("Interface\\Addons\\EERaidAdmin\\textures\\Slash") |
end |
end |
end |
end |
function EELoot:DrawInterestAll() |
_debug("DrawInterestAll") |
if self.Anchor:IsVisible() then |
self:ClearInterest() |
if db.CollectedLoot[SelectedLoot] then |
for i = 1, #raidPlayers do |
local name, class, subgroup, online = raidPlayers[i].name, raidPlayers[i].class, raidPlayers[i].subgroup, raidPlayers[i].online |
if subgroup <= __raidActiveGroups then self:DrawInterest(name) end |
if i == __raidActivePlayers then break end |
end |
-- draw winner |
if db.CollectedLoot[SelectedLoot].winner then |
local t_index = playerToBarIndex[db.CollectedLoot[SelectedLoot].winner] |
if t_index <= __raidActivePlayers then |
local i_r, i_g, i_b = _adjustColorToIndex(t_index, 0.50, 0.50, 0) |
bars[t_index].texture:SetTexture(0,0,0,0) |
bars[t_index]:SetBackdropColor(i_r,i_g,i_b,0.95) |
end |
elseif #_WinnerNames > 0 then |
for i, player in ipairs(_WinnerNames) do |
local t_index = playerToBarIndex[player] |
if t_index <= __raidActivePlayers then |
local i_r, i_g, i_b = _adjustColorToIndex(t_index, 0.50, 0.50, 0) |
bars[t_index].texture:SetTexture(0,0,0,0) |
bars[t_index]:SetBackdropColor(i_r,i_g,i_b,0.95) |
end |
end |
end |
end |
end |
end |
function EELoot:UpdateInterest(player, interest) |
_debug("UpdateInterest: "..player..", "..interest) |
if not db.CollectedLoot[SelectedLoot] then return end |
if not db.CollectedLoot[SelectedLoot].interest then |
_debug("> first interest") |
db.CollectedLoot[SelectedLoot].interest = {} |
end |
db.CollectedLoot[SelectedLoot].interest[player] = {} |
db.CollectedLoot[SelectedLoot].interest[player]['interest'] = interest |
self:DrawInterest(player) |
self.ButtonStartRoll:Enable() |
end |
function EELoot:OnCommReceived(prefix, message, distribution, sender) |
_debug("OnCommReceived") |
local tokens = { strsplit(";", message) } |
if prefix == "LSRC" then |
-- |
if tokens[1] == "EQUIP" then |
if not (playerToBarIndex[sender] <= __raidActivePlayers) then return end |
if tokens[2] == "FAIL" then |
--db.CollectedLoot[SelectedLoot].interest[sender].currentitem = "Ðе найден в кÑÑе Ñ Ð¸Ð³Ñока, повÑоÑиÑÑ?" |
bars[playerToBarIndex[sender]].ItemText:SetText("Ðе найден в кÑÑе Ñ Ð¸Ð³Ñока, повÑоÑиÑÑ?") |
bars[playerToBarIndex[sender]].ItemText:Show() |
else |
local itemInfo = GetItemInfo(tokens[2]) |
local _, itemLink, _, _, _, _, _, _, _, _ = GetItemInfo(tokens[2]) |
_debug("EQUIP POLL:"..sender..":"..tokens[2]) |
if itemInfo then |
_debug("Could obtain item - drawing") |
--db.CollectedLoot[SelectedLoot].interest[sender].currentitem = itemLink |
bars[playerToBarIndex[sender]].ItemText:SetText(itemLink) |
bars[playerToBarIndex[sender]].ItemText:Show() |
else |
_debug("Could not obtain item") |
-- TODO: |
tempTooltip = CreateFrame("GameTooltip", "TempTooltip", UIParent, "GameTooltipTemplate") |
tempTooltip:SetHyperlink("item:".._getItemId(tokens[2])..":0:0:0:0:0:0:0") |
--db.CollectedLoot[SelectedLoot].interest[sender].currentitem = "Ðе найден в локалÑном кÑÑе, повÑоÑиÑÑ?" |
bars[playerToBarIndex[sender]].ItemText:SetText("Ðе найден в локалÑном кÑÑе, повÑоÑиÑÑ?") |
bars[playerToBarIndex[sender]].ItemText:Show() |
end |
end |
elseif tokens[1] == "LOOT" then |
self:UpdateInterest(sender, tokens[2]) |
end |
------------------------------------------------------------------ |
end |
end |
local function __________() |
-- ignore, IDE cheat |
end |
function EELoot:LootDropDownMenu_SelectLoot() |
_debug("LootDropDownMenu_SelectLoot") |
local ndb=this:GetID() |
UIDropDownMenu_SetSelectedID(self.LootDropDownMenu, ndb) |
SelectedLoot=ndb |
self.StandardRoll:Enable() |
self.QuickRoll:Enable() |
self:DrawPlayerBars() |
self:CalculateWinner() |
self:DrawInterestAll() |
end |
function EELoot:LootDropDownMenu_OnShow() |
_debug("LootDropDownMenu_OnShow") |
UIDropDownMenu_Initialize(self.LootDropDownMenu, self.LootDropDownMenu_Initialize) |
UIDropDownMenu_SetSelectedID(self.LootDropDownMenu, SelectedLoot) |
UIDropDownMenu_SetWidth(self.LootDropDownMenu, 300) |
end |
function EELoot:LootDropDownMenu_Initialize() |
_debug("LootDropDownMenu_Initialize") |
info_loot = {} |
info_loot.fontObject = "GameFontNormalLarge" |
if #db.CollectedLoot > 0 then |
for i = 1, #db.CollectedLoot do |
info_loot.text = db.CollectedLoot[i].itemLink |
info_loot.checked = i == SelectedLoot |
info_loot.func = function() EELoot:LootDropDownMenu_SelectLoot() end |
-- info_loot.icon = "Interface\\Addons\\EERaidAdmin\\textures\\Slash" --TODO --Interface\\Buttons\\UI-GroupLoot-Pass-Up |
UIDropDownMenu_AddButton(info_loot) |
end |
else |
info_loot.text = "ÐÐµÑ ÐÑедмеÑа" |
info_loot.checked = true |
UIDropDownMenu_AddButton(info_loot) |
end |
end |
function EELoot:OnInitialize() |
_debug("OnInitialize") |
self.db = LibStub("AceDB-3.0"):New("EERaidAdminDB") |
db = self.db.global |
if db.CollectedLoot == nil then db.CollectedLoot = {}; end |
--if db.CollectedLootInterest == nil then db.CollectedLootInterest = {}; end |
self:RegisterComm("LSRC") |
-- |
self:RegisterBucketEvent("RAID_ROSTER_UPDATE", 1, "RAID_ROSTER_UPDATE") |
self:RegisterBucketEvent("CHAT_MSG_SYSTEM", 0.5, "CHAT_MSG_SYSTEM_SLOW") |
self:RegisterEvent("LOOT_OPENED") |
self:RegisterEvent("LOOT_CLOSED") |
self:RegisterEvent("LOOT_SLOT_CLEARED") |
self:RegisterEvent("PLAYER_TARGET_CHANGED") |
self:RegisterEvent("CHAT_MSG_SYSTEM") |
-- |
self:CreateFrames() |
self:OfflineMode() |
if #db.CollectedLoot > 0 then |
self.StandardRoll:Enable() |
self.QuickRoll:Enable() |
end |
self.Anchor:Hide() |
end |
function EELoot:CreateFrames() |
-- |
--tempTooltip = CreateFrame("GameTooltip", nil, UIParent, "GameTooltipTemplate") |
self.Anchor = CreateFrame("Frame",nil,UIParent) |
self.Anchor:SetFrameStrata("HIGH") |
self.Anchor:SetScript("OnShow", function() EELoot:OnShow() end ) |
self.Anchor:SetScript("OnHide", function() EELoot:OnHide() end ) |
self.LootStatus = CreateFrame("Frame", nil, self.Anchor) |
self.LootStatus:SetPoint("TOPLEFT", self.Anchor, "TOPLEFT", 20, -40) |
self.LootStatus:SetPoint("TOPRIGHT", self.Anchor, "TOPRIGHT", -20, -40) |
self.LootStatus:SetBackdrop( {bgFile = "Interface\\Addons\\EERaidAdmin\\textures\\Stripes", |
edgeFile = nil, tile = true, tileSize = 32, edgeSize = nil, |
insets = { left = 0, right = 0, top = 0, bottom = 0 }}); |
self.LootStatus:SetBackdropColor(0,0,0,0); |
self.LootStatus:SetHeight(55) |
-- first line of buttons |
local RollType = self.LootStatus:CreateFontString(nil,"ARTWORK","GameFontNormal") |
RollType:SetText("Тип Ñолла") |
RollType:SetPoint("TOPLEFT",self.LootStatus,"TOPLEFT",10,-5) |
self.LootTargetName = self.LootStatus:CreateFontString(nil,"ARTWORK","GameFontNormal") |
self.LootTargetName:SetPoint("TOPRIGHT",self.LootStatus,"TOPRIGHT",-10,-5) |
self.StandardRoll = CreateFrame("Button",nil,self.LootStatus,"OptionsButtonTemplate") |
self.StandardRoll:SetHeight(28) |
self.StandardRoll:SetText("ÐолнÑй") |
self.StandardRoll:SetScript("OnClick", function() |
EELoot:SendStandardRoll() |
end ) |
self.StandardRoll:Disable() |
self.StandardRoll:SetPoint("BOTTOMLEFT",self.LootStatus,"BOTTOMLEFT", 5, 5) |
self.QuickRoll = CreateFrame("Button",nil,self.LootStatus,"OptionsButtonTemplate") |
self.QuickRoll:SetHeight(28) |
self.QuickRoll:SetText("ÐÑÑÑÑÑй") |
self.QuickRoll:SetScript("OnClick", function() |
EELoot:SendQuickRoll() |
end ) |
self.QuickRoll:Disable() |
self.QuickRoll:SetPoint("LEFT",self.StandardRoll,"RIGHT",5,0) |
self.LootDropDownMenu = CreateFrame("Button","LootDropDownMenu",self.LootStatus,"UIDropDownMenuTemplate") |
self.LootDropDownMenu:SetScript("OnDoubleClick", function() |
if IsShiftKeyDown() then |
EELoot:LootAnnounceGuild() |
else |
EELoot:CollectLoot() |
end |
end ) |
self.LootDropDownMenu:SetScript("OnShow", function() |
EELoot:LootDropDownMenu_OnShow() |
end ) |
self.LootDropDownMenu:SetPoint("BOTTOMRIGHT",self.LootStatus,"BOTTOMRIGHT", 10, 2) |
self.BarList = CreateFrame("Frame", nil, self.Anchor) |
self.BarList:SetPoint("TOPLEFT", self.LootStatus, "BOTTOMLEFT", 0, -20) |
self.BarList:SetPoint("TOPRIGHT", self.LootStatus, "BOTTOMRIGHT", 0, -20) |
self.BarList:SetHeight(500) |
-- second line of buttons |
self.ButtonStartRoll = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") |
self.ButtonStartRoll:SetHeight(28) |
self.ButtonStartRoll:SetText("РазÑолиÑÑ") |
self.ButtonStartRoll:SetScript("OnClick", function() |
EELoot:SendStartRoll() |
end ) |
self.ButtonStartRoll:SetPoint("BOTTOMLEFT",self.Anchor,"BOTTOMLEFT",20,20) |
--self.ButtonStartRoll:Disable() |
self.GiveLootButton = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") |
self.GiveLootButton:SetHeight(28) |
self.GiveLootButton:SetText("ÐÐµÐºÐ¾Ð¼Ñ Ð²ÑдаÑÑ") |
self.GiveLootButton:SetScript("OnClick", function() |
EELoot:GiveLoot() |
EELoot:DrawInterestAll() |
end ) |
self.GiveLootButton:SetPoint("BOTTOMRIGHT",self.Anchor,"BOTTOMRIGHT",-20,20) |
self.GiveLootButton:Disable() |
self.WinnerButton = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") |
self.WinnerButton:SetHeight(28) |
self.WinnerButton:SetText("ÐÑигÑал") |
self.WinnerButton:SetScript("OnClick", function() |
EELoot:DeclareWinner() |
EELoot:DrawInterestAll() |
end ) |
self.WinnerButton:SetPoint("RIGHT",self.GiveLootButton,"LEFT",-20,0) |
self.WinnerButton:Disable() |
self.DeductKarma = CreateFrame("EditBox", "DeductKarma", self.Anchor, "InputBoxTemplate") |
self.DeductKarma:SetWidth(40) |
self.DeductKarma:SetHeight(22) |
self.DeductKarma:SetAutoFocus(false) |
self.DeductKarma:ClearFocus() |
self.DeductKarma:SetPoint("RIGHT",self.WinnerButton,"LEFT",-5,0) |
local DeductKarmaLabel = self.Anchor:CreateFontString(nil,"ARTWORK","GameFontNormal") |
DeductKarmaLabel:SetText("â") |
DeductKarmaLabel:SetPoint("RIGHT",self.DeductKarma,"LEFT",-7,0) |
end |
function EELoot:OnShow() |
_debug("OnShow") |
self:UpdateRaidPlayerInfo() |
self:DrawPlayerBars() |
self:CalculateWinner() |
self:DrawInterestAll() |
end |
function EELoot:OnHide() |
_debug("OnHide") |
end |
function EELoot:OnEnable() |
_debug("OnEnable") |
end |
function EELoot:OnDisable() |
_debug("OnDisable") |
end |
EERaid = EERaidAdmin:NewModule("EERaid", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0") |
------ VARIABLES |
---- GLOBALS |
local db --= EERaidAdmin.db |
local __IsDebugging = 0 |
local __raidActiveGroups = EERaidAdmin.__raidActiveGroups |
local __raidActivePlayers = EERaidAdmin.__raidActivePlayers |
local ServerDateTime = EERaidAdmin.ServerDateTime |
--EERaid.db = db.global |
---- LOCALS |
local _RaidUpdateInterval = 30 -- seconds |
local _RaidKarmaEmissionInterval = 60 * 15 -- 15 minutes |
------ HELPER FUNCTIONS |
local function _color(r, g, b, msg) |
if type(r) == "table" then |
if r.r then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end |
end |
t_color = string.format("|cff%02x%02x%02x", r*255, g*255, b*255) |
if msg ~= '' then |
return t_color..msg..'|r' |
else |
return t_color |
end |
end |
local function _message(msg, label) |
local output = "" |
output = _color(0,1,1, 'EERaid: ') |
if label then |
output = output.._color(0,0.7,0.7, label..': ') |
end |
output = output..msg |
print(output) |
end |
local function _debug(msg, fatal) |
if __IsDebugging == 1 or fatal then |
EERaid:Print("|cffdd0000debug: "..msg.."|r") |
end |
end |
local function _sortRaidSubgroupAsc(a, b) |
if (not a) then |
return false |
elseif (not b) then |
return true |
else |
return (a.subgroup < b.subgroup) |
end |
end |
function EERaid:GetRaidPlayers() |
_debug("GetRaidPlayers") |
local raidPlayers = {} |
local raidPlayersIndexes = {} |
-- name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName = GetGuildRosterInfo(index) |
for i = 1, GetNumRaidMembers() do |
local name, _, subgroup, _, _, class, _, online, _, _, _ = GetRaidRosterInfo(i) |
raidPlayers[i] = { name=name, class=class, subgroup=subgroup, online=online } |
end |
-- sort, according to the subgroup number (1,2..) |
table.sort(raidPlayers, _sortRaidSubgroupAsc) |
-- fill the playerToBarIndex lookup table |
for i, v in pairs(raidPlayers) do |
raidPlayersIndexes[v.name] = i |
end |
return raidPlayers, raidPlayersIndexes |
end |
function EERaid:GetActiveRaidPlayers() |
_debug("GetActiveRaidPlayers") |
local raidPlayers = {} |
local raidPlayersIndexes = {} |
for i = 1, GetNumRaidMembers() do |
local name, _, subgroup, _, _, class, _, online, _, _, _ = GetRaidRosterInfo(i) |
if subgroup <= __raidActiveGroups then |
raidPlayers[i] = { name=name, class=class, subgroup=subgroup, online=online } |
end |
end |
-- sort, according to the subgroup number (1,2..) |
table.sort(raidPlayers, _sortRaidSubgroupAsc) |
-- fill the playerToBarIndex lookup table |
for i, v in pairs(raidPlayers) do |
raidPlayersIndexes[v.name] = i |
end |
return raidPlayers, raidPlayersIndexes |
end |
function EERaid:IsRaidActive() |
_debug("IsRaidActive") |
if db._RaidStartedAt and db._RaidStartedAt ~= 0 then |
_debug("> active") |
return true |
else |
_debug("> inactive") |
return false |
end |
end |
function EERaid:ContinueRaid() |
_debug("ContinueRaid") |
self.SwitchRaid:SetText("ÐÑÑановиÑÑ Ñейд") |
self.Updater:Show() |
_message(db._RaidStartedAt, "Рейд пÑодолжаеÑÑÑ") |
end |
function EERaid:StartRaid() |
_debug("StartRaid") |
if EERaid:IsRaidActive() then _debug("Рейд Ñже наÑаÑ", 1); return false; end |
db._RaidStartedAt = ServerDateTime() |
db._TimeSinceLastUpdate = 0 |
--db._TimeSinceLastPeriodicKarma = 0 |
-- |
self.SwitchRaid:SetText("ÐÑÑановиÑÑ Ñейд") |
--EEKarma:KarmaMassAdd("GUILD", 2, 3, "ÐаÑма за наÑало Ñейда: "..GetRealZoneText()) |
EPGP:StartRecurringEP(GetRealZoneText().."(EERA)", 100); -- start recurring EP |
self.Updater:Show() |
-- |
_message(db._RaidStartedAt, "Рейд наÑаÑ") |
end |
function EERaid:EndRaid() |
_debug("EndRaid") |
if not EERaid:IsRaidActive() then _debug("Рейд Ñже законÑен", 1); return false; end |
db._RaidStartedAt = nil |
db._TimeSinceLastUpdate = 0 |
--db._TimeSinceLastPeriodicKarma = 0 |
-- |
self.SwitchRaid:SetText("ÐаÑаÑÑ Ñейд") |
--EEKarma:KarmaMassAdd("GUILD", 2, 3, "ÐаÑма за ÐºÐ¾Ð½ÐµÑ Ñейда") |
--EEKarma:DBCompact() |
EPGP:StopRecurringEP(); -- stop recurring EP |
self.Updater:Hide() |
-- |
_message(ServerDateTime(), "Рейд законÑен") |
end |
function EERaid:PeriodicalUpdater(self, elapsed) |
db._TimeSinceLastUpdate = db._TimeSinceLastUpdate + elapsed |
end |
function EERaid:CreateFrames() |
self.Anchor = CreateFrame("Frame",nil,UIParent) |
self.Anchor:SetScript("OnShow", function() EERaid:OnShow() end ) |
self.Anchor:SetScript("OnHide", function() EERaid:OnHide() end ) |
self.Anchor:SetFrameStrata("HIGH") |
-- FIXME: est' li drugie varianty delat' pereodicheskie zapuski |
self.Updater = CreateFrame("Frame",nil, UIParent) |
self.Updater:SetScript("OnUpdate", function(self, elapsed) EERaid:PeriodicalUpdater(self, elapsed) end ) |
self.Updater:Hide() |
self.SwitchRaid = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") |
self.SwitchRaid:SetText("ÐаÑаÑÑ Ñейд") |
self.SwitchRaid:SetHeight(30) |
self.SwitchRaid:SetWidth(160) |
self.SwitchRaid:SetScript("OnClick", function() |
if not EERaid:IsRaidActive() then |
EERaid:StartRaid() |
else |
EERaid:EndRaid() |
end |
end ) |
self.SwitchRaid:SetPoint("CENTER", self.Anchor) |
end |
function EERaid:OnShow() |
_debug("OnShow") |
end |
function EERaid:OnHide() |
_debug("OnHide") |
end |
function EERaid:OnInitialize() |
_debug("OnInitialize") |
self.db = LibStub("AceDB-3.0"):New("EERaidAdminDB") |
db = self.db.global |
-- preinitialize |
if db._RaidStartedAt == nil then db._RaidStartedAt = 0; end |
if db._TimeSinceLastUpdate == nil then db._TimeSinceLastUpdate = 0; end |
--if db._TimeSinceLastPeriodicKarma == nil then db._TimeSinceLastPeriodicKarma = 0; end |
self:RegisterComm("LSRC") |
-- self:RegisterEvent("RAID_ROSTER_UPDATE") |
-- self:RegisterEvent("LOOT_OPENED") |
-- self:RegisterEvent("LOOT_CLOSED") |
-- self:RegisterEvent("LOOT_SLOT_CLEARED") |
-- self:RegisterEvent("PLAYER_TARGET_CHANGED") |
-- self:RegisterEvent("CHAT_MSG_SYSTEM") |
self:CreateFrames() |
self.Anchor:Hide() |
-- TODO: continue raid |
if db._RaidStartedAt and db._RaidStartedAt ~= 0 then |
self:ContinueRaid() |
end |
end |
function EERaid:OnCommReceived(prefix, message, distribution, sender) |
_debug("OnCommReceived") |
local tokens = { strsplit(";", message) } |
if prefix == "LSRC" then |
-- |
end |
end |
function EERaid:OnEnable() |
_debug("OnEnable") |
end |
function EERaid:OnDisable() |
_debug("OnDisable") |
end |
<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="AceBucket-3.0.lua"/> |
</Ui> |
--- A bucket to catch events in. **AceBucket-3.0** provides throttling of events that fire in bursts and |
-- your addon only needs to know about the full burst. |
-- |
-- This Bucket implementation works as follows:\\ |
-- Initially, no schedule is running, and its waiting for the first event to happen.\\ |
-- The first event will start the bucket, and get the scheduler running, which will collect all |
-- events in the given interval. When that interval is reached, the bucket is pushed to the |
-- callback and a new schedule is started. When a bucket is empty after its interval, the scheduler is |
-- stopped, and the bucket is only listening for the next event to happen, basically back in its initial state. |
-- |
-- In addition, the buckets collect information about the "arg1" argument of the events that fire, and pass those as a |
-- table to your callback. This functionality was mostly designed for the UNIT_* events.\\ |
-- The table will have the different values of "arg1" as keys, and the number of occurances as their value, e.g.\\ |
-- { ["player"] = 2, ["target"] = 1, ["party1"] = 1 } |
-- |
-- **AceBucket-3.0** can be embeded into your addon, either explicitly by calling AceBucket: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 AceBucket itself.\\ |
-- It is recommended to embed AceBucket, otherwise you'll have to specify a custom `self` on all calls you |
-- make into AceBucket. |
-- @usage |
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("BucketExample", "AceBucket-3.0") |
-- |
-- function MyAddon:OnEnable() |
-- -- Register a bucket that listens to all the HP related events, |
-- -- and fires once per second |
-- self:RegisterBucketEvent({"UNIT_HEALTH", "UNIT_MAXHEALTH"}, 1, "UpdateHealth") |
-- end |
-- |
-- function MyAddon:UpdateHealth(units) |
-- if units.player then |
-- print("Your HP changed!") |
-- end |
-- end |
-- @class file |
-- @name AceBucket-3.0.lua |
-- @release $Id: AceBucket-3.0.lua 781 2009-04-05 10:01:39Z nevcairiel $ |
local MAJOR, MINOR = "AceBucket-3.0", 3 |
local AceBucket, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
if not AceBucket then return end -- No Upgrade needed |
AceBucket.buckets = AceBucket.buckets or {} |
AceBucket.embeds = AceBucket.embeds or {} |
-- the libraries will be lazyly bound later, to avoid errors due to loading order issues |
local AceEvent, AceTimer |
-- local upvalues |
local type = type |
local next = next |
local pairs = pairs |
local select = select |
local tonumber = tonumber |
local tostring = tostring |
local bucketCache = setmetatable({}, {__mode='k'}) |
--[[ |
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", table.concat(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, ...) |
return Dispatchers[select('#', ...)](func, ...) |
end |
-- FireBucket ( bucket ) |
-- |
-- send the bucket to the callback function and schedule the next FireBucket in interval seconds |
local function FireBucket(bucket) |
local received = bucket.received |
-- we dont want to fire empty buckets |
if next(received) then |
local callback = bucket.callback |
if type(callback) == "string" then |
safecall(bucket.object[callback], bucket.object, received) |
else |
safecall(callback, received) |
end |
for k in pairs(received) do |
received[k] = nil |
end |
-- if the bucket was not empty, schedule another FireBucket in interval seconds |
bucket.timer = AceTimer.ScheduleTimer(bucket, FireBucket, bucket.interval, bucket) |
else -- if it was empty, clear the timer and wait for the next event |
bucket.timer = nil |
end |
end |
-- BucketHandler ( event, arg1 ) |
-- |
-- callback func for AceEvent |
-- stores arg1 in the received table, and schedules the bucket if necessary |
local function BucketHandler(self, event, arg1) |
if arg1 == nil then |
arg1 = "nil" |
end |
self.received[arg1] = (self.received[arg1] or 0) + 1 |
-- if we are not scheduled yet, start a timer on the interval for our bucket to be cleared |
if not self.timer then |
self.timer = AceTimer.ScheduleTimer(self, FireBucket, self.interval, self) |
end |
end |
-- RegisterBucket( event, interval, callback, isMessage ) |
-- |
-- event(string or table) - the event, or a table with the events, that this bucket listens to |
-- interval(int) - time between bucket fireings |
-- callback(func or string) - function pointer, or method name of the object, that gets called when the bucket is cleared |
-- isMessage(boolean) - register AceEvent Messages instead of game events |
local function RegisterBucket(self, event, interval, callback, isMessage) |
-- try to fetch the librarys |
if not AceEvent or not AceTimer then |
AceEvent = LibStub:GetLibrary("AceEvent-3.0", true) |
AceTimer = LibStub:GetLibrary("AceTimer-3.0", true) |
if not AceEvent or not AceTimer then |
error(MAJOR .. " requires AceEvent-3.0 and AceTimer-3.0", 3) |
end |
end |
if type(event) ~= "string" and type(event) ~= "table" then error("Usage: RegisterBucket(event, interval, callback): 'event' - string or table expected.", 3) end |
if not callback then |
if type(event) == "string" then |
callback = event |
else |
error("Usage: RegisterBucket(event, interval, callback): cannot omit callback when event is not a string.", 3) |
end |
end |
if not tonumber(interval) then error("Usage: RegisterBucket(event, interval, callback): 'interval' - number expected.", 3) end |
if type(callback) ~= "string" and type(callback) ~= "function" then error("Usage: RegisterBucket(event, interval, callback): 'callback' - string or function or nil expected.", 3) end |
if type(callback) == "string" and type(self[callback]) ~= "function" then error("Usage: RegisterBucket(event, interval, callback): 'callback' - method not found on target object.", 3) end |
local bucket = next(bucketCache) |
if bucket then |
bucketCache[bucket] = nil |
else |
bucket = { handler = BucketHandler, received = {} } |
end |
bucket.object, bucket.callback, bucket.interval = self, callback, tonumber(interval) |
local regFunc = isMessage and AceEvent.RegisterMessage or AceEvent.RegisterEvent |
if type(event) == "table" then |
for _,e in pairs(event) do |
regFunc(bucket, e, "handler") |
end |
else |
regFunc(bucket, event, "handler") |
end |
local handle = tostring(bucket) |
AceBucket.buckets[handle] = bucket |
return handle |
end |
--- Register a Bucket for an event (or a set of events) |
-- @param event The event to listen for, or a table of events. |
-- @param interval The Bucket interval (burst interval) |
-- @param callback The callback function, either as a function reference, or a string pointing to a method of the addon object. |
-- @return The handle of the bucket (for unregistering) |
-- @usage |
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceBucket-3.0") |
-- MyAddon:RegisterBucketEvent("BAG_UPDATE", 0.2, "UpdateBags") |
-- |
-- function MyAddon:UpdateBags() |
-- -- do stuff |
-- end |
function AceBucket:RegisterBucketEvent(event, interval, callback) |
return RegisterBucket(self, event, interval, callback, false) |
end |
--- Register a Bucket for an AceEvent-3.0 addon message (or a set of messages) |
-- @param message The message to listen for, or a table of messages. |
-- @param interval The Bucket interval (burst interval) |
-- @param callback The callback function, either as a function reference, or a string pointing to a method of the addon object. |
-- @return The handle of the bucket (for unregistering) |
-- @usage |
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceBucket-3.0") |
-- MyAddon:RegisterBucketEvent("SomeAddon_InformationMessage", 0.2, "ProcessData") |
-- |
-- function MyAddon:ProcessData() |
-- -- do stuff |
-- end |
function AceBucket:RegisterBucketMessage(message, interval, callback) |
return RegisterBucket(self, message, interval, callback, true) |
end |
--- Unregister any events and messages from the bucket and clear any remaining data. |
-- @param handle The handle of the bucket as returned by RegisterBucket* |
function AceBucket:UnregisterBucket(handle) |
local bucket = AceBucket.buckets[handle] |
if bucket then |
AceEvent.UnregisterAllEvents(bucket) |
AceEvent.UnregisterAllMessages(bucket) |
-- clear any remaining data in the bucket |
for k in pairs(bucket.received) do |
bucket.received[k] = nil |
end |
if bucket.timer then |
AceTimer.CancelTimer(bucket, bucket.timer) |
bucket.timer = nil |
end |
AceBucket.buckets[handle] = nil |
-- store our bucket in the cache |
bucketCache[bucket] = true |
end |
end |
--- Unregister all buckets of the current addon object (or custom "self"). |
function AceBucket:UnregisterAllBuckets() |
-- hmm can we do this more efficient? (it is not done often so shouldn't matter much) |
for handle, bucket in pairs(AceBucket.buckets) do |
if bucket.object == self then |
AceBucket.UnregisterBucket(self, handle) |
end |
end |
end |
-- embedding and embed handling |
local mixins = { |
"RegisterBucketEvent", |
"RegisterBucketMessage", |
"UnregisterBucket", |
"UnregisterAllBuckets", |
} |
-- Embeds AceBucket into the target object making the functions from the mixins list available on target:.. |
-- @param target target object to embed AceBucket in |
function AceBucket:Embed( target ) |
for _, v in pairs( mixins ) do |
target[v] = self[v] |
end |
self.embeds[target] = true |
return target |
end |
function AceBucket:OnEmbedDisable( target ) |
target:UnregisterAllBuckets() |
end |
for addon in pairs(AceBucket.embeds) do |
AceBucket:Embed(addon) |
end |
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info |
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke |
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS! |
local LibStub = _G[LIBSTUB_MAJOR] |
if not LibStub or LibStub.minor < LIBSTUB_MINOR then |
LibStub = LibStub or {libs = {}, minors = {} } |
_G[LIBSTUB_MAJOR] = LibStub |
LibStub.minor = LIBSTUB_MINOR |
function LibStub:NewLibrary(major, minor) |
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)") |
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.") |
local oldminor = self.minors[major] |
if oldminor and oldminor >= minor then return nil end |
self.minors[major], self.libs[major] = minor, self.libs[major] or {} |
return self.libs[major], oldminor |
end |
function LibStub:GetLibrary(major, silent) |
if not self.libs[major] and not silent then |
error(("Cannot find a library instance of %q."):format(tostring(major)), 2) |
end |
return self.libs[major], self.minors[major] |
end |
function LibStub:IterateLibraries() return pairs(self.libs) end |
setmetatable(LibStub, { __call = LibStub.GetLibrary }) |
end |
<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> |
--- **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 766 2009-04-04 08:26:05Z nevcairiel $ |
local MAJOR,MINOR = "AceLocale-3.0", 2 |
local AceLocale, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
if not AceLocale then return end -- no upgrade needed |
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. Can only be set on the default locale. |
-- @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) |
if silent and not isDefault then |
error("Usage: NewLocale(application, locale[, isDefault[, silent]]): 'silent' can only be specified for the default locale", 2) |
end |
-- GAME_LOCALE allows translators to test translations of addons without having that wow client installed |
-- Ammo: I still think this is a bad idea, for instance an addon that checks for some ingame string will fail, just because some other addon |
-- gives the user the illusion that they can run in a different locale? Ditch this whole thing or allow a setting per 'application'. I'm of the |
-- opinion to remove this. |
local gameLocale = GAME_LOCALE or gameLocale |
if locale ~= gameLocale and not isDefault then |
return -- nop, we don't need these translations |
end |
local app = AceLocale.apps[application] |
if not app then |
app = setmetatable({}, silent and readmetasilent or readmeta) |
AceLocale.apps[application] = app |
AceLocale.appnames[app] = application |
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 |
<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> |
--[[ $Id: CallbackHandler-1.0.lua 846 2009-09-17 10:51:12Z ammo $ ]] |
local MAJOR, MINOR = "CallbackHandler-1.0", 5 |
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} |
local type = type |
local pcall = pcall |
local pairs = pairs |
local assert = assert |
local concat = table.concat |
local loadstring = loadstring |
local next = next |
local select = select |
local type = type |
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", concat(OLD_ARGS, ", ")):gsub("ARGS", concat(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, OnUsed, OnUnused) |
-- TODO: Remove this after beta has gone out |
assert(not OnUsed and not OnUnused, "ACE-80: OnUsed/OnUnused are deprecated. Callbacks are now done to registry.OnUsed and registry.OnUnused") |
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" |
if type(self)~="table" and type(self)~="string" then |
error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string 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. |
--- **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, rescheduled |
-- 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.1s. This constant may change |
-- in the future, but for now it seemed like a good compromise in efficiency and accuracy. |
-- |
-- All `:Schedule` functions will return a handle to the current timer, which you will need to store if you |
-- need to cancel or reschedule 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 769 2009-04-04 11:05:08Z nevcairiel $ |
--[[ |
Basic assumptions: |
* In a typical system, we do more re-scheduling per second than there are timer pulses per second |
* Regardless of timer implementation, we cannot guarantee timely delivery due to FPS restriction (may be as low as 10) |
This implementation: |
CON: The smallest timer interval is constrained by HZ (currently 1/10s). |
PRO: It will still correctly fire any timer slower than HZ over a length of time, e.g. 0.11s interval -> 90 times over 10 seconds |
PRO: In lag bursts, the system simly skips missed timer intervals to decrease load |
CON: Algorithms depending on a timer firing "N times per minute" will fail |
PRO: (Re-)scheduling is O(1) with a VERY small constant. It's a simple linked list insertion in a hash bucket. |
CAUTION: The BUCKETS constant constrains how many timers can be efficiently handled. With too many hash collisions, performance will decrease. |
Major assumptions upheld: |
- ALLOWS scheduling multiple timers with the same funcref/method |
- ALLOWS scheduling more timers during OnUpdate processing |
- ALLOWS unscheduling ANY timer (including the current running one) at any time, including during OnUpdate processing |
]] |
local MAJOR, MINOR = "AceTimer-3.0", 5 |
local AceTimer, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
if not AceTimer then return end -- No upgrade needed |
AceTimer.hash = AceTimer.hash or {} -- Array of [0..BUCKET-1] = linked list of timers (using .next member) |
-- Linked list gets around ACE-88 and ACE-90. |
AceTimer.selfs = AceTimer.selfs or {} -- Array of [self]={[handle]=timerobj, [handle2]=timerobj2, ...} |
AceTimer.frame = AceTimer.frame or CreateFrame("Frame", "AceTimer30Frame") |
local type = type |
local next = next |
local pairs = pairs |
local select = select |
local tostring = tostring |
local floor = floor |
local max = max |
-- Simple ONE-SHOT timer cache. Much more efficient than a full compost for our purposes. |
local timerCache = nil |
--[[ |
Timers will not be fired more often than HZ-1 times per second. |
Keep at intended speed PLUS ONE or we get bitten by floating point rounding errors (n.5 + 0.1 can be n.599999) |
If this is ever LOWERED, all existing timers need to be enforced to have a delay >= 1/HZ on lib upgrade. |
If this number is ever changed, all entries need to be rehashed on lib upgrade. |
]] |
local HZ = 11 |
--[[ |
Prime for good distribution |
If this number is ever changed, all entries need to be rehashed on lib upgrade. |
]] |
local BUCKETS = 131 |
local hash = AceTimer.hash |
for i=1,BUCKETS do |
hash[i] = hash[i] or false -- make it an integer-indexed array; it's faster than hashes |
end |
--[[ |
xpcall safecall implementation |
]] |
local xpcall = xpcall |
local function errorhandler(err) |
return geterrorhandler()(err) |
end |
local function CreateDispatcher(argCount) |
local code = [[ |
local xpcall, eh = ... -- our arguments are received as unnamed values in "..." since we don't have a proper function declaration |
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", table.concat(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, ...) |
return Dispatchers[select('#', ...)](func, ...) |
end |
local lastint = floor(GetTime() * HZ) |
-- -------------------------------------------------------------------- |
-- OnUpdate handler |
-- |
-- traverse buckets, always chasing "now", and fire timers that have expired |
local function OnUpdate() |
local now = GetTime() |
local nowint = floor(now * HZ) |
-- Have we passed into a new hash bucket? |
if nowint == lastint then return end |
local soon = now + 1 -- +1 is safe as long as 1 < HZ < BUCKETS/2 |
-- Pass through each bucket at most once |
-- Happens on e.g. instance loads, but COULD happen on high local load situations also |
for curint = (max(lastint, nowint - BUCKETS) + 1), nowint do -- loop until we catch up with "now", usually only 1 iteration |
local curbucket = (curint % BUCKETS)+1 |
-- Yank the list of timers out of the bucket and empty it. This allows reinsertion in the currently-processed bucket from callbacks. |
local nexttimer = hash[curbucket] |
hash[curbucket] = false -- false rather than nil to prevent the array from becoming a hash |
while nexttimer do |
local timer = nexttimer |
nexttimer = timer.next |
local when = timer.when |
if when < soon then |
-- Call the timer func, either as a method on given object, or a straight function ref |
local callback = timer.callback |
if type(callback) == "string" then |
safecall(timer.object[callback], timer.object, timer.arg) |
elseif callback then |
safecall(callback, timer.arg) |
else |
-- probably nilled out by CancelTimer |
timer.delay = nil -- don't reschedule it |
end |
local delay = timer.delay -- NOW make a local copy, can't do it earlier in case the timer cancelled itself in the callback |
if not delay then |
-- single-shot timer (or cancelled) |
AceTimer.selfs[timer.object][tostring(timer)] = nil |
timerCache = timer |
else |
-- repeating timer |
local newtime = when + delay |
if newtime < now then -- Keep lag from making us firing a timer unnecessarily. (Note that this still won't catch too-short-delay timers though.) |
newtime = now + delay |
end |
timer.when = newtime |
-- add next timer execution to the correct bucket |
local bucket = (floor(newtime * HZ) % BUCKETS) + 1 |
timer.next = hash[bucket] |
hash[bucket] = timer |
end |
else -- if when>=soon |
-- reinsert (yeah, somewhat expensive, but shouldn't be happening too often either due to hash distribution) |
timer.next = hash[curbucket] |
hash[curbucket] = timer |
end -- if when<soon ... else |
end -- while nexttimer do |
end -- for curint=lastint,nowint |
lastint = nowint |
end |
-- --------------------------------------------------------------------- |
-- Reg( callback, delay, arg, repeating ) |
-- |
-- callback( function or string ) - direct function ref or method name in our object for the callback |
-- delay(int) - delay for the timer |
-- arg(variant) - any argument to be passed to the callback function |
-- repeating(boolean) - repeating timer, or oneshot |
-- |
-- returns the handle of the timer for later processing (canceling etc) |
local function Reg(self, callback, delay, arg, repeating) |
if type(callback) ~= "string" and type(callback) ~= "function" then |
local error_origin = repeating and "ScheduleRepeatingTimer" or "ScheduleTimer" |
error(MAJOR..": " .. error_origin .. "(callback, delay, arg): 'callback' - function or method name expected.", 3) |
end |
if type(callback) == "string" then |
if type(self)~="table" then |
local error_origin = repeating and "ScheduleRepeatingTimer" or "ScheduleTimer" |
error(MAJOR..": " .. error_origin .. "(\"methodName\", delay, arg): 'self' - must be a table.", 3) |
end |
if type(self[callback]) ~= "function" then |
local error_origin = repeating and "ScheduleRepeatingTimer" or "ScheduleTimer" |
error(MAJOR..": " .. error_origin .. "(\"methodName\", delay, arg): 'methodName' - method not found on target object.", 3) |
end |
end |
if delay < (1 / (HZ - 1)) then |
delay = 1 / (HZ - 1) |
end |
-- Create and stuff timer in the correct hash bucket |
local now = GetTime() |
local timer = timerCache or {} -- Get new timer object (from cache if available) |
timerCache = nil |
timer.object = self |
timer.callback = callback |
timer.delay = (repeating and delay) |
timer.arg = arg |
timer.when = now + delay |
local bucket = (floor((now+delay)*HZ) % BUCKETS) + 1 |
timer.next = hash[bucket] |
hash[bucket] = timer |
-- Insert timer in our self->handle->timer registry |
local handle = tostring(timer) |
local selftimers = AceTimer.selfs[self] |
if not selftimers then |
selftimers = {} |
AceTimer.selfs[self] = selftimers |
end |
selftimers[handle] = timer |
selftimers.__ops = (selftimers.__ops or 0) + 1 |
return handle |
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 arg An optional argument to be passed to the callback function. |
-- @usage |
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("TimerTest", "AceTimer-3.0") |
-- |
-- function MyAddon:OnEnable() |
-- self:ScheduleTimer("TimerFeedback", 5) |
-- end |
-- |
-- function MyAddon:TimerFeedback() |
-- print("5 seconds passed") |
-- end |
function AceTimer:ScheduleTimer(callback, delay, arg) |
return Reg(self, callback, delay, arg) |
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 arg An optional argument to be passed to the callback function. |
-- @usage |
-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("TimerTest", "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(callback, delay, arg) |
return Reg(self, callback, delay, arg, true) |
end |
--- Cancels a timer with the given handle, 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 `handle` is valid |
-- and the timer has not fired yet or was canceled before. |
-- @param handle The handle of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer` |
-- @param silent If true, no error is raised if the timer handle is invalid (expired or already canceled) |
-- @return True if the timer was successfully cancelled. |
function AceTimer:CancelTimer(handle, silent) |
if not handle then return end -- nil handle -> bail out without erroring |
if type(handle) ~= "string" then |
error(MAJOR..": CancelTimer(handle): 'handle' - expected a string", 2) -- for now, anyway |
end |
local selftimers = AceTimer.selfs[self] |
local timer = selftimers and selftimers[handle] |
if silent then |
if timer then |
timer.callback = nil -- don't run it again |
timer.delay = nil -- if this is the currently-executing one: don't even reschedule |
-- The timer object is removed in the OnUpdate loop |
end |
return not not timer -- might return "true" even if we double-cancel. we'll live. |
else |
if not timer then |
geterrorhandler()(MAJOR..": CancelTimer(handle[, silent]): '"..tostring(handle).."' - no such timer registered") |
return false |
end |
if not timer.callback then |
geterrorhandler()(MAJOR..": CancelTimer(handle[, silent]): '"..tostring(handle).."' - timer already cancelled or expired") |
return false |
end |
timer.callback = nil -- don't run it again |
timer.delay = nil -- if this is the currently-executing one: don't even reschedule |
return true |
end |
end |
--- Cancels all timers registered to the current addon object ('self') |
function AceTimer:CancelAllTimers() |
if not(type(self) == "string" or type(self) == "table") then |
error(MAJOR..": CancelAllTimers(): 'self' - must be a string or a table",2) |
end |
if self == AceTimer then |
error(MAJOR..": CancelAllTimers(): supply a meaningful 'self'", 2) |
end |
local selftimers = AceTimer.selfs[self] |
if selftimers then |
for handle,v in pairs(selftimers) do |
if type(v) == "table" then -- avoid __ops, etc |
AceTimer.CancelTimer(self, handle, true) |
end |
end |
end |
end |
--- Returns the time left for a timer with the given handle, registered by the current addon object ('self'). |
-- This function will raise a warning when the handle is invalid, but not stop execution. |
-- @param handle The handle of the timer, as returned by `:ScheduleTimer` or `:ScheduleRepeatingTimer` |
-- @return The time left on the timer, or false if the handle is invalid. |
function AceTimer:TimeLeft(handle) |
if not handle then return end |
if type(handle) ~= "string" then |
error(MAJOR..": TimeLeft(handle): 'handle' - expected a string", 2) -- for now, anyway |
end |
local selftimers = AceTimer.selfs[self] |
local timer = selftimers and selftimers[handle] |
if not timer then |
geterrorhandler()(MAJOR..": TimeLeft(handle): '"..tostring(handle).."' - no such timer registered") |
return false |
end |
return timer.when - GetTime() |
end |
-- --------------------------------------------------------------------- |
-- PLAYER_REGEN_ENABLED: Run through our .selfs[] array step by step |
-- and clean it out - otherwise the table indices can grow indefinitely |
-- if an addon starts and stops a lot of timers. AceBucket does this! |
-- |
-- See ACE-94 and tests/AceTimer-3.0-ACE-94.lua |
local lastCleaned = nil |
local function OnEvent(this, event) |
if event~="PLAYER_REGEN_ENABLED" then |
return |
end |
-- Get the next 'self' to process |
local selfs = AceTimer.selfs |
local self = next(selfs, lastCleaned) |
if not self then |
self = next(selfs) |
end |
lastCleaned = self |
if not self then -- should only happen if .selfs[] is empty |
return |
end |
-- Time to clean it out? |
local list = selfs[self] |
if (list.__ops or 0) < 250 then -- 250 slosh indices = ~10KB wasted (max!). For one 'self'. |
return |
end |
-- Create a new table and copy all members over |
local newlist = {} |
local n=0 |
for k,v in pairs(list) do |
newlist[k] = v |
n=n+1 |
end |
newlist.__ops = 0 -- Reset operation count |
-- And since we now have a count of the number of live timers, check that it's reasonable. Emit a warning if not. |
if n>BUCKETS then |
DEFAULT_CHAT_FRAME:AddMessage(MAJOR..": Warning: The addon/module '"..tostring(self).."' has "..n.." live timers. Surely that's not intended?") |
end |
selfs[self] = newlist |
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 |
-- --------------------------------------------------------------------- |
-- Debug tools (expose copies of internals to test suites) |
AceTimer.debug = AceTimer.debug or {} |
AceTimer.debug.HZ = HZ |
AceTimer.debug.BUCKETS = BUCKETS |
-- --------------------------------------------------------------------- |
-- Finishing touchups |
AceTimer.frame:SetScript("OnUpdate", OnUpdate) |
AceTimer.frame:SetScript("OnEvent", OnEvent) |
AceTimer.frame:RegisterEvent("PLAYER_REGEN_ENABLED") |
-- In theory, we should hide&show the frame based on there being timers or not. |
-- However, this job is fairly expensive, and the chance that there will |
-- actually be zero timers running is diminuitive to say the lest. |
<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> |
<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> |
--- 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 766 2009-04-04 08:26:05Z nevcairiel $ |
local MAJOR, MINOR = "AceEvent-3.0", 3 |
local AceEvent = LibStub:NewLibrary(MAJOR, MINOR) |
if not AceEvent then return end |
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 always be called with the event as the first argument, and if supplied, the `arg` as second argument. |
-- 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 always be called with the event as the first argument, and if supplied, the `arg` as second argument. |
-- 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 |
<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> |
--- **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 859 2009-10-05 16:09:42Z mikk $ |
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 |
-- local upvalues |
local _G = _G |
local pairs = pairs |
local select = select |
local type = type |
local tostring = tostring |
local strfind = string.find |
local strsub = string.sub |
local max = math.max |
local format = format |
local tconcat = table.concat |
-- GLOBALS: DEFAULT_CHAT_FRAME, error, 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 |
-- A library to use for Debug information that provides a central way |
-- to enable/disable debugging on a special debug frame. |
local MAJOR_VERSION = "LibDebug-1.0" |
local MINOR_VERSION = tonumber(("$Revision: 1023 $"):match("%d+")) or 0 |
local lib, oldMinor = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION) |
if not lib then return end |
lib.frame = lib.frame or CreateFrame("Frame", MAJOR_VERSION.."_Frame", UIParent) |
local frame = lib.frame |
-- See if we're updating the lib, if so copy the old lib's isDebugging boolean |
local isDebugging = lib.isDebugging and lib:isDebugging() or false |
-- The main frame. |
frame:EnableMouse() |
frame:SetMinResize(300, 100) |
frame:SetWidth(400) |
frame:SetHeight(400) |
frame:SetPoint("CENTER", UIParent) |
frame:SetFrameStrata("TOOLTIP") |
frame:SetBackdrop( |
{ |
bgFile = "Interface\\Tooltips\\ChatBubble-Background", |
edgeFile = "Interface\\Tooltips\\ChatBubble-BackDrop", |
tile = true, |
tileSize = 16, |
edgeSize = 16, |
insets = { left=16, right=16, top=16, bottom=16 } |
}) |
frame:SetBackdropColor(0, 0, 0, 1) |
-- The titlebar/drag bar. |
frame:SetMovable(true) |
frame:SetClampedToScreen(true) |
frame.title = CreateFrame("Button", nil, frame) |
frame.title:SetNormalFontObject("GameFontNormal") |
frame.title:SetText(MAJOR_VERSION) |
frame.title:SetPoint("TOPLEFT", frame, "TOPLEFT", 8, -8) |
frame.title:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -8, -8) |
frame.title:SetHeight(8) |
frame.title:SetHighlightTexture( |
"Interface\\FriendsFrame\\UI-FriendsFrame-HighlightBar") |
frame.title:SetScript("OnMouseDown", |
function (self) self:GetParent():StartMoving() end) |
frame.title:SetScript("OnMouseUp", |
function (self) self:GetParent():StopMovingOrSizing() end) |
-- The sizing button. |
frame:SetResizable(true) |
frame.sizer = CreateFrame("Button", nil, frame) |
frame.sizer:SetHeight(16) |
frame.sizer:SetWidth(16) |
frame.sizer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT") |
frame.sizer:SetScript("OnMouseDown", |
function (self) |
self:GetParent():StartSizing("BOTTOMRIGHT") |
end) |
frame.sizer:SetScript("OnMouseUp", |
function (self) self:GetParent():StopMovingOrSizing() |
end) |
local line1 = frame.sizer:CreateTexture(nil, "BACKGROUND") |
line1:SetWidth(14) |
line1:SetHeight(14) |
line1:SetPoint("BOTTOMRIGHT", -8, 8) |
line1:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
local x = 0.1 * 14/17 |
line1:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) |
local line2 = frame.sizer:CreateTexture(nil, "BACKGROUND") |
line2:SetWidth(8) |
line2:SetHeight(8) |
line2:SetPoint("BOTTOMRIGHT", -8, 8) |
line2:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") |
local x = 0.1 * 8/17 |
line2:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) |
frame.bottom = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") |
frame.bottom:SetJustifyH("LEFT") |
frame.bottom:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 8, 8) |
frame.bottom:SetPoint("BOTTOMRIGHT", frame.sizer) |
frame.bottom:SetHeight(8) |
frame.bottom:SetText("Mouse wheel to scroll (with shift scroll top/bottom). Title bar drags. Bottom-right corner resizes.") |
-- The scrolling message frame with all the debug info. |
frame.msg = CreateFrame("ScrollingMessageFrame", nil, frame) |
frame.msg:SetPoint("TOPLEFT", frame.title, "BOTTOMLEFT") |
frame.msg:SetPoint("TOPRIGHT", frame.title, "BOTTOMRIGHT") |
frame.msg:SetPoint("BOTTOM", frame.bottom, "TOP", 0, 8) |
frame.msg:SetMaxLines(10000) |
frame.msg:SetFading(false) |
frame.msg:SetFontObject("GameFontHighlightLeft") |
frame.msg:EnableMouseWheel(true) |
-- Hook scrolling to scroll up down with mousewheel. shift mousewheel |
-- scroll all the way to the top/bottom. |
local function ScrollingFunction(self, arg) |
if arg > 0 then |
if IsShiftKeyDown() then self:ScrollToTop() else self:ScrollUp() end |
elseif arg < 0 then |
if IsShiftKeyDown() then self:ScrollToBottom() else self:ScrollDown() end |
end |
end |
frame.msg:SetScript("OnMouseWheel", ScrollingFunction) |
function lib:DebugStub(fmt, ...) end |
local function GetTimeShort() |
local t = GetTime() |
return t - math.floor(t / 100) * 100 |
end |
local function GetCaller() |
local trace = debugstack(3, 1, 0) |
return trace:match("([^\\]-): in function") or trace |
end |
function lib:Debug(fmt, ...) |
frame.msg:AddMessage(string.format("%6.3f (%s): "..fmt, |
GetTimeShort(), GetCaller(), ...)) |
end |
local mt = getmetatable(lib) or {} |
mt.__call = lib.DebugStub |
setmetatable(lib, mt) |
function lib:IsDebugging() |
return isDebugging |
end |
function lib:EnableDebugging(val) |
local mt = getmetatable(self) |
if val == false then |
mt.__call = lib.DebugStub |
isDebugging = false |
else |
mt.__call = lib.Debug |
isDebugging = true |
end |
end |
function lib:Toggle() |
if frame:IsShown() then |
frame:Hide() |
else |
frame:Show() |
end |
end |
frame:Hide() |
<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> |
--- **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 777 2009-04-04 20:16:09Z nevcairiel $ |
local MAJOR, MINOR = "AceAddon-3.0", 5 |
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 |
local tinsert, tconcat = table.insert, table.concat |
local fmt = string.format |
local pairs, next, type = pairs, next, type |
--[[ |
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 |
--- 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.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 |
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) |
return AceAddon:EnableAddon(self) |
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) |
for k, v in pairs(mixins) do |
target[k] = v |
end |
for k, v in pairs(pmixins) do |
target[k] = target[k] or v |
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. |
for name, module in pairs(addon.modules) do |
self:EnableAddon(module) |
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. |
for name, module in pairs(addon.modules) do |
self:DisableAddon(module) |
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) |
if event == "ADDON_LOADED" 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) |
end |
<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> |
--- 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 801 2009-04-09 20:34:28Z nevcairiel $ |
--[[ |
AceConfigCmd-3.0 |
Handles commandline optionstable access |
REQUIRES: AceConsole-3.0 for command registration (loaded on demand) |
]] |
-- TODO: handle disabled / hidden |
-- TODO: implement handlers for all types |
-- TODO: plugin args |
local MAJOR, MINOR = "AceConfigCmd-3.0", 9 |
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" |
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 |
-- 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 showhelp(info, inputpos, tab, 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 |
table.insert(sortTbl, k) |
refTbl[k] = v |
end |
end |
table.sort(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 _,k in ipairs(sortTbl) do |
local v = refTbl[k] |
if not pickfirstset(v.cmdHidden, v.hidden, false) 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)..":") |
showhelp(info, inputpos, v, true) |
elseif v.type ~= "description" and v.type ~= "header" then |
local key = k:gsub(" ", "_") |
print(" |cffffff78"..key.."|r - "..(desc or name or "")) |
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 |
-- 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" |
-- 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 = string.find(info.input, " *([^ ]+) *", inputpos) |
if not arg then |
showhelp(info, inputpos, tab) |
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 string.gmatch(str, "[^ ]+") do |
--parse option=on etc |
local opt, val = string.match(v,'(.+)=(.+)') |
--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 |
if tab.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 |
<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> |
--- 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 832 2009-09-01 11:03:04Z nevcairiel $ |
local MAJOR, MINOR = "AceConfigRegistry-3.0", 11 |
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 |
----------------------------------------------------------------------- |
-- 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(): "..table.concat(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 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=optstringfunc, |
iconCoords=optmethodtable, |
handler=opttable, |
get=optmethodfalse, |
set=optmethodfalse, |
func=optmethodfalse, |
arg={["*"]=true}, |
width=optstring, |
} |
local typedkeys={ |
header={}, |
description={ |
image=optstringfunc, |
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=optstringfunc, |
imageCoords=optmethodtable, |
imageHeight=optnumber, |
imageWidth=optnumber, |
}, |
input={ |
pattern=optstring, |
usage=optstring, |
control=optstring, |
dialogControl=optstring, |
dropdownControl=optstring, |
multiline=optboolnumber, |
}, |
toggle={ |
tristate=optbool, |
}, |
tristate={ |
}, |
range={ |
min=optnumber, |
max=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, |
}, |
multiselect={ |
values=ismethodtable, |
style=optstring, |
tristate=optbool, |
control=optstring, |
dialogControl=optstring, |
dropdownControl=optstring, |
}, |
color={ |
hasAlpha=optbool, |
}, |
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. |
function AceConfigRegistry:RegisterOptionsTable(appName, options) |
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] 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] 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 |
<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> |
--- 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 802 2009-04-11 12:12:37Z nevcairiel $ |
--[[ |
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") |
local cfgdlg = LibStub("AceConfigDialog-3.0") |
--TODO: local cfgdrp = LibStub("AceConfigDropdown-3.0") |
-- ------------------------------------------------------------------- |
-- :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) |
-- @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 |
<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> |
--- AceConfigDialog-3.0 generates AceGUI-3.0 based windows based on option tables. |
-- @class file |
-- @name AceConfigDialog-3.0 |
-- @release $Id: AceConfigDialog-3.0.lua 836 2009-09-07 07:59:58Z ammo $ |
local LibStub = LibStub |
local MAJOR, MINOR = "AceConfigDialog-3.0", 36 |
local AceConfigDialog = LibStub:NewLibrary(MAJOR, MINOR) |
if not AceConfigDialog then return end |
AceConfigDialog.OpenFrames = AceConfigDialog.OpenFrames or {} |
AceConfigDialog.Status = AceConfigDialog.Status or {} |
AceConfigDialog.frame = AceConfigDialog.frame or CreateFrame("Frame") |
AceConfigDialog.frame.apps = AceConfigDialog.frame.apps or {} |
AceConfigDialog.frame.closing = AceConfigDialog.frame.closing or {} |
local gui = LibStub("AceGUI-3.0") |
local reg = LibStub("AceConfigRegistry-3.0") |
local select = select |
local pairs = pairs |
local type = type |
local assert = assert |
local tinsert = tinsert |
local tremove = tremove |
local error = error |
local table = table |
local unpack = unpack |
local string = string |
local next = next |
local math = math |
local _ |
--[[ |
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", table.concat(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, ...) |
return Dispatchers[select('#', ...)](func, ...) |
end |
local width_multiplier = 170 |
--[[ |
Group Types |
Tree - All Descendant Groups will all become nodes on the tree, direct child options will appear above the tree |
- Descendant Groups with inline=true and thier children will not become nodes |
Tab - Direct Child Groups will become tabs, direct child options will appear above the tab control |
- Grandchild groups will default to inline unless specified otherwise |
Select- Same as Tab but with entries in a dropdown rather than tabs |
Inline Groups |
- Will not become nodes of a select group, they will be effectivly part of thier parent group seperated by a border |
- If declared on a direct child of a root node of a select group, they will appear above the group container control |
- When a group is displayed inline, all descendants will also be inline members of the group |
]] |
-- Recycling functions |
local new, del, copy |
--newcount, delcount,createdcount,cached = 0,0,0 |
do |
local pool = setmetatable({},{__mode='k'}) |
function new() |
--newcount = newcount + 1 |
local t = next(pool) |
if t then |
pool[t] = nil |
return t |
else |
--createdcount = createdcount + 1 |
return {} |
end |
end |
function copy(t) |
local c = new() |
for k, v in pairs(t) do |
c[k] = v |
end |
return c |
end |
function del(t) |
--delcount = delcount + 1 |
for k in pairs(t) do |
t[k] = nil |
end |
pool[t] = true |
end |
-- function cached() |
-- local n = 0 |
-- for k in pairs(pool) do |
-- n = n + 1 |
-- end |
-- return n |
-- end |
end |
-- 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 |
--gets an option from a given group, checking plugins |
local function GetSubOption(group, key) |
if group.plugins then |
for plugin, t in pairs(group.plugins) do |
if t[key] then |
return t[key] |
end |
end |
end |
return group.args[key] |
end |
--Option member type definitions, used to decide how to access it |
--Is the member Inherited from parent options |
local isInherited = { |
set = true, |
get = true, |
func = true, |
confirm = true, |
validate = true, |
disabled = true, |
hidden = true |
} |
--Does a string type mean a literal value, instead of the default of a method of the handler |
local stringIsLiteral = { |
name = true, |
desc = true, |
icon = true, |
usage = true, |
width = true, |
image = true, |
fontSize = true, |
} |
--Is Never a function or method |
local allIsLiteral = { |
type = true, |
descStyle = true, |
imageWidth = true, |
imageHeight = true, |
} |
--gets the value for a member that could be a function |
--function refs are called with an info arg |
--every other type is returned |
local function GetOptionsMemberValue(membername, option, options, path, appName, ...) |
--get definition for the member |
local inherits = isInherited[membername] |
--get the member of the option, traversing the tree if it can be inherited |
local member |
if inherits then |
local group = options |
if group[membername] ~= nil then |
member = group[membername] |
end |
for i = 1, #path do |
group = GetSubOption(group, path[i]) |
if group[membername] ~= nil then |
member = group[membername] |
end |
end |
else |
member = option[membername] |
end |
--check if we need to call a functon, or if we have a literal value |
if ( not allIsLiteral[membername] ) and ( type(member) == "function" or ((not stringIsLiteral[membername]) and type(member) == "string") ) then |
--We have a function to call |
local info = new() |
--traverse the options table, picking up the handler and filling the info with the path |
local handler |
local group = options |
handler = group.handler or handler |
for i = 1, #path do |
group = GetSubOption(group, path[i]) |
info[i] = path[i] |
handler = group.handler or handler |
end |
info.options = options |
info.appName = appName |
info[0] = appName |
info.arg = option.arg |
info.handler = handler |
info.option = option |
info.type = option.type |
info.uiType = 'dialog' |
info.uiName = MAJOR |
local a, b, c ,d |
--using 4 returns for the get of a color type, increase if a type needs more |
if type(member) == "function" then |
--Call the function |
a,b,c,d = member(info, ...) |
else |
--Call the method |
if handler and handler[member] then |
a,b,c,d = handler[member](handler, info, ...) |
else |
error(string.format("Method %s doesn't exist in handler for type %s", member, membername)) |
end |
end |
del(info) |
return a,b,c,d |
else |
--The value isnt a function to call, return it |
return member |
end |
end |
--[[calls an options function that could be inherited, method name or function ref |
local function CallOptionsFunction(funcname ,option, options, path, appName, ...) |
local info = new() |
local func |
local group = options |
local handler |
--build the info table containing the path |
-- pick up functions while traversing the tree |
if group[funcname] ~= nil then |
func = group[funcname] |
end |
handler = group.handler or handler |
for i, v in ipairs(path) do |
group = GetSubOption(group, v) |
info[i] = v |
if group[funcname] ~= nil then |
func = group[funcname] |
end |
handler = group.handler or handler |
end |
info.options = options |
info[0] = appName |
info.arg = option.arg |
local a, b, c ,d |
if type(func) == "string" then |
if handler and handler[func] then |
a,b,c,d = handler[func](handler, info, ...) |
else |
error(string.format("Method %s doesn't exist in handler for type func", func)) |
end |
elseif type(func) == "function" then |
a,b,c,d = func(info, ...) |
end |
del(info) |
return a,b,c,d |
end |
--]] |
--tables to hold orders and names for options being sorted, will be created with new() |
--prevents needing to call functions repeatedly while sorting |
local tempOrders |
local tempNames |
local function compareOptions(a,b) |
if not a then |
return true |
end |
if not b then |
return false |
end |
local OrderA, OrderB = tempOrders[a] or 100, tempOrders[b] or 100 |
if OrderA == OrderB then |
local NameA = (type(tempNames[a] == "string") and tempNames[a]) or "" |
local NameB = (type(tempNames[b] == "string") and tempNames[b]) or "" |
return NameA:upper() < NameB:upper() |
end |
if OrderA < 0 then |
if OrderB > 0 then |
return false |
end |
else |
if OrderB < 0 then |
return true |
end |
end |
return OrderA < OrderB |
end |
--builds 2 tables out of an options group |
-- keySort, sorted keys |
-- opts, combined options from .plugins and args |
local function BuildSortedOptionsTable(group, keySort, opts, options, path, appName) |
tempOrders = new() |
tempNames = new() |
if group.plugins then |
for plugin, t in pairs(group.plugins) do |
for k, v in pairs(t) do |
if not opts[k] then |
tinsert(keySort, k) |
opts[k] = v |
path[#path+1] = k |
tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName) |
tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName) |
path[#path] = nil |
end |
end |
end |
end |
for k, v in pairs(group.args) do |
if not opts[k] then |
tinsert(keySort, k) |
opts[k] = v |
path[#path+1] = k |
tempOrders[k] = GetOptionsMemberValue("order", v, options, path, appName) |
tempNames[k] = GetOptionsMemberValue("name", v, options, path, appName) |
path[#path] = nil |
end |
end |
table.sort(keySort, compareOptions) |
del(tempOrders) |
del(tempNames) |
end |
local function DelTree(tree) |
if tree.children then |
local childs = tree.children |
for i = 1, #childs do |
DelTree(childs[i]) |
del(childs[i]) |
end |
del(childs) |
end |
end |
local function CleanUserData(widget, event) |
local user = widget:GetUserDataTable() |
if user.path then |
del(user.path) |
end |
if widget.type == "TreeGroup" then |
local tree = user.tree |
widget:SetTree(nil) |
if tree then |
for i = 1, #tree do |
DelTree(tree[i]) |
del(tree[i]) |
end |
del(tree) |
end |
end |
if widget.type == "TabGroup" then |
widget:SetTabs(nil) |
if user.tablist then |
del(user.tablist) |
end |
end |
if widget.type == "DropdownGroup" then |
widget:SetGroupList(nil) |
if user.grouplist then |
del(user.grouplist) |
end |
end |
end |
-- - Gets a status table for the given appname and options path. |
-- @param appName The application name as given to `:RegisterOptionsTable()` |
-- @param path The path to the options (a table with all group keys) |
-- @return |
function AceConfigDialog:GetStatusTable(appName, path) |
local status = self.Status |
if not status[appName] then |
status[appName] = {} |
status[appName].status = {} |
status[appName].children = {} |
end |
status = status[appName] |
if path then |
for i = 1, #path do |
local v = path[i] |
if not status.children[v] then |
status.children[v] = {} |
status.children[v].status = {} |
status.children[v].children = {} |
end |
status = status.children[v] |
end |
end |
return status.status |
end |
--- Selects the specified path in the options window. |
-- The path specified has to match the keys of the groups in the table. |
-- @param appName The application name as given to `:RegisterOptionsTable()` |
-- @param ... The path to the key that should be selected |
function AceConfigDialog:SelectGroup(appName, ...) |
local path = new() |
local app = reg:GetOptionsTable(appName) |
if not app then |
error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2) |
end |
local options = app("dialog", MAJOR) |
local group = options |
local status = self:GetStatusTable(appName, path) |
if not status.groups then |
status.groups = {} |
end |
status = status.groups |
local treevalue |
local treestatus |
for n = 1, select('#',...) do |
local key = select(n, ...) |
if group.childGroups == "tab" or group.childGroups == "select" then |
--if this is a tab or select group, select the group |
status.selected = key |
--children of this group are no longer extra levels of a tree |
treevalue = nil |
else |
--tree group by default |
if treevalue then |
--this is an extra level of a tree group, build a uniquevalue for it |
treevalue = treevalue.."\001"..key |
else |
--this is the top level of a tree group, the uniquevalue is the same as the key |
treevalue = key |
if not status.groups then |
status.groups = {} |
end |
--save this trees status table for any extra levels or groups |
treestatus = status |
end |
--make sure that the tree entry is open, and select it. |
--the selected group will be overwritten if a child is the final target but still needs to be open |
treestatus.selected = treevalue |
treestatus.groups[treevalue] = true |
end |
--move to the next group in the path |
group = GetSubOption(group, key) |
if not group then |
break |
end |
tinsert(path, key) |
status = self:GetStatusTable(appName, path) |
if not status.groups then |
status.groups = {} |
end |
status = status.groups |
end |
del(path) |
reg:NotifyChange(appName) |
end |
local function OptionOnMouseOver(widget, event) |
--show a tooltip/set the status bar to the desc text |
local user = widget:GetUserDataTable() |
local opt = user.option |
local options = user.options |
local path = user.path |
local appName = user.appName |
GameTooltip:SetOwner(widget.frame, "ANCHOR_TOPRIGHT") |
local name = GetOptionsMemberValue("name", opt, options, path, appName) |
local desc = GetOptionsMemberValue("desc", opt, options, path, appName) |
local usage = GetOptionsMemberValue("usage", opt, options, path, appName) |
local descStyle = opt.descStyle |
if descStyle and descStyle ~= "tooltip" then return end |
GameTooltip:SetText(name, 1, .82, 0, 1) |
if opt.type == 'multiselect' then |
GameTooltip:AddLine(user.text,0.5, 0.5, 0.8, 1) |
end |
if type(desc) == "string" then |
GameTooltip:AddLine(desc, 1, 1, 1, 1) |
end |
if type(usage) == "string" then |
GameTooltip:AddLine("Usage: "..usage, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1) |
end |
GameTooltip:Show() |
end |
local function OptionOnMouseLeave(widget, event) |
GameTooltip:Hide() |
end |
local function GetFuncName(option) |
local type = option.type |
if type == 'execute' then |
return 'func' |
else |
return 'set' |
end |
end |
local function confirmPopup(appName, rootframe, basepath, info, message, func, ...) |
if not StaticPopupDialogs["ACECONFIGDIALOG30_CONFIRM_DIALOG"] then |
StaticPopupDialogs["ACECONFIGDIALOG30_CONFIRM_DIALOG"] = {} |
end |
local t = StaticPopupDialogs["ACECONFIGDIALOG30_CONFIRM_DIALOG"] |
for k in pairs(t) do |
t[k] = nil |
end |
t.text = message |
t.button1 = ACCEPT |
t.button2 = CANCEL |
local dialog, oldstrata |
t.OnAccept = function() |
safecall(func, unpack(t)) |
if dialog and oldstrata then |
dialog:SetFrameStrata(oldstrata) |
end |
AceConfigDialog:Open(appName, rootframe, basepath and unpack(basepath)) |
del(info) |
end |
t.OnCancel = function() |
if dialog and oldstrata then |
dialog:SetFrameStrata(oldstrata) |
end |
AceConfigDialog:Open(appName, rootframe, basepath and unpack(basepath)) |
del(info) |
end |
for i = 1, select('#', ...) do |
t[i] = select(i, ...) or false |
end |
t.timeout = 0 |
t.whileDead = 1 |
t.hideOnEscape = 1 |
dialog = StaticPopup_Show("ACECONFIGDIALOG30_CONFIRM_DIALOG") |
if dialog then |
oldstrata = dialog:GetFrameStrata() |
dialog:SetFrameStrata("TOOLTIP") |
end |
end |
local function ActivateControl(widget, event, ...) |
--This function will call the set / execute handler for the widget |
--widget:GetUserDataTable() contains the needed info |
local user = widget:GetUserDataTable() |
local option = user.option |
local options = user.options |
local path = user.path |
local info = new() |
local func |
local group = options |
local funcname = GetFuncName(option) |
local handler |
local confirm |
local validate |
--build the info table containing the path |
-- pick up functions while traversing the tree |
if group[funcname] ~= nil then |
func = group[funcname] |
end |
handler = group.handler or handler |
confirm = group.confirm |
validate = group.validate |
for i = 1, #path do |
local v = path[i] |
group = GetSubOption(group, v) |
info[i] = v |
if group[funcname] ~= nil then |
func = group[funcname] |
end |
handler = group.handler or handler |
if group.confirm ~= nil then |
confirm = group.confirm |
end |
if group.validate ~= nil then |
validate = group.validate |
end |
end |
info.options = options |
info.appName = user.appName |
info.arg = option.arg |
info.handler = handler |
info.option = option |
info.type = option.type |
info.uiType = 'dialog' |
info.uiName = MAJOR |
local name |
if type(option.name) == "function" then |
name = option.name(info) |
elseif type(option.name) == "string" then |
name = option.name |
else |
name = "" |
end |
local usage = option.usage |
local pattern = option.pattern |
local validated = true |
if option.type == "input" then |
if type(pattern)=="string" then |
if not strmatch(..., pattern) then |
validated = false |
end |
end |
end |
local success |
if validated and option.type ~= "execute" then |
if type(validate) == "string" then |
if handler and handler[validate] then |
success, validated = safecall(handler[validate], handler, info, ...) |
if not success then validated = false end |
else |
error(string.format("Method %s doesn't exist in handler for type execute", validate)) |
end |
elseif type(validate) == "function" then |
success, validated = safecall(validate, info, ...) |
if not success then validated = false end |
end |
end |
local rootframe = user.rootframe |
if type(validated) == "string" then |
--validate function returned a message to display |
if rootframe.SetStatusText then |
rootframe:SetStatusText(validated) |
else |
-- TODO: do something else. |
end |
PlaySound("igPlayerInviteDecline") |
del(info) |
return true |
elseif not validated then |
--validate returned false |
if rootframe.SetStatusText then |
if usage then |
rootframe:SetStatusText(name..": "..usage) |
else |
if pattern then |
rootframe:SetStatusText(name..": Expected "..pattern) |
else |
rootframe:SetStatusText(name..": Invalid Value") |
end |
end |
else |
-- TODO: do something else |
end |
PlaySound("igPlayerInviteDecline") |
del(info) |
return true |
else |
local confirmText = option.confirmText |
--call confirm func/method |
if type(confirm) == "string" then |
if handler and handler[confirm] then |
success, confirm = safecall(handler[confirm], handler, info, ...) |
if success and type(confirm) == "string" then |
confirmText = confirm |
confirm = true |
elseif not success then |
confirm = false |
end |
else |
error(string.format("Method %s doesn't exist in handler for type confirm", confirm)) |
end |
elseif type(confirm) == "function" then |
success, confirm = safecall(confirm, info, ...) |
if success and type(confirm) == "string" then |
confirmText = confirm |
confirm = true |
elseif not success then |
confirm = false |
end |
end |
--confirm if needed |
if type(confirm) == "boolean" then |
if confirm then |
if not confirmText then |
local name, desc = option.name, option.desc |
if type(name) == "function" then |
name = name(info) |
end |
if type(desc) == "function" then |
desc = desc(info) |
end |
confirmText = name |
if desc then |
confirmText = confirmText.." - "..desc |
end |
end |
local iscustom = user.rootframe:GetUserData('iscustom') |
local rootframe |
if iscustom then |
rootframe = user.rootframe |
end |
local basepath = user.rootframe:GetUserData('basepath') |
if type(func) == "string" then |
if handler and handler[func] then |
confirmPopup(user.appName, rootframe, basepath, info, confirmText, handler[func], handler, info, ...) |
else |
error(string.format("Method %s doesn't exist in handler for type func", func)) |
end |
elseif type(func) == "function" then |
confirmPopup(user.appName, rootframe, basepath, info, confirmText, func, info, ...) |
end |
--func will be called and info deleted when the confirm dialog is responded to |
return |
end |
end |
--call the function |
if type(func) == "string" then |
if handler and handler[func] then |
safecall(handler[func],handler, info, ...) |
else |
error(string.format("Method %s doesn't exist in handler for type func", func)) |
end |
elseif type(func) == "function" then |
safecall(func,info, ...) |
end |
local iscustom = user.rootframe:GetUserData('iscustom') |
local basepath = user.rootframe:GetUserData('basepath') |
--full refresh of the frame, some controls dont cause this on all events |
if option.type == "color" then |
if event == "OnValueConfirmed" then |
if iscustom then |
AceConfigDialog:Open(user.appName, user.rootframe, basepath and unpack(basepath)) |
else |
AceConfigDialog:Open(user.appName, basepath and unpack(basepath)) |
end |
end |
elseif option.type == "range" then |
if event == "OnMouseUp" then |
if iscustom then |
AceConfigDialog:Open(user.appName, user.rootframe, basepath and unpack(basepath)) |
else |
AceConfigDialog:Open(user.appName, basepath and unpack(basepath)) |
end |
end |
--multiselects don't cause a refresh on 'OnValueChanged' only 'OnClosed' |
elseif option.type == "multiselect" then |
user.valuechanged = true |
else |
if iscustom then |
AceConfigDialog:Open(user.appName, user.rootframe, basepath and unpack(basepath)) |
else |
AceConfigDialog:Open(user.appName, basepath and unpack(basepath)) |
end |
end |
end |
del(info) |
end |
local function ActivateSlider(widget, event, value) |
local option = widget:GetUserData('option') |
local min, max, step = option.min or 0, option.max or 100, option.step |
if step then |
value = math.floor((value - min) / step + 0.5) * step + min |
else |
value = math.max(math.min(value,max),min) |
end |
ActivateControl(widget,event,value) |
end |
--called from a checkbox that is part of an internally created multiselect group |
--this type is safe to refresh on activation of one control |
local function ActivateMultiControl(widget, event, ...) |
ActivateControl(widget, event, widget:GetUserData('value'), ...) |
local user = widget:GetUserDataTable() |
local iscustom = user.rootframe:GetUserData('iscustom') |
local basepath = user.rootframe:GetUserData('basepath') |
if iscustom then |
AceConfigDialog:Open(user.appName, user.rootframe, basepath and unpack(basepath)) |
else |
AceConfigDialog:Open(user.appName, basepath and unpack(basepath)) |
end |
end |
local function MultiControlOnClosed(widget, event, ...) |
local user = widget:GetUserDataTable() |
if user.valuechanged then |
local iscustom = user.rootframe:GetUserData('iscustom') |
local basepath = user.rootframe:GetUserData('basepath') |
if iscustom then |
AceConfigDialog:Open(user.appName, user.rootframe, basepath and unpack(basepath)) |
else |
AceConfigDialog:Open(user.appName, basepath and unpack(basepath)) |
end |
end |
end |
local function FrameOnClose(widget, event) |
local appName = widget:GetUserData('appName') |
AceConfigDialog.OpenFrames[appName] = nil |
gui:Release(widget) |
end |
local function CheckOptionHidden(option, options, path, appName) |
--check for a specific boolean option |
local hidden = pickfirstset(option.dialogHidden,option.guiHidden) |
if hidden ~= nil then |
return hidden |
end |
return GetOptionsMemberValue("hidden", option, options, path, appName) |
end |
local function CheckOptionDisabled(option, options, path, appName) |
--check for a specific boolean option |
local disabled = pickfirstset(option.dialogDisabled,option.guiDisabled) |
if disabled ~= nil then |
return disabled |
end |
return GetOptionsMemberValue("disabled", option, options, path, appName) |
end |
--[[ |
local function BuildTabs(group, options, path, appName) |
local tabs = new() |
local text = new() |
local keySort = new() |
local opts = new() |
BuildSortedOptionsTable(group, keySort, opts, options, path, appName) |
for i = 1, #keySort do |
local k = keySort[i] |
local v = opts[k] |
if v.type == "group" then |
path[#path+1] = k |
local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) |
local hidden = CheckOptionHidden(v, options, path, appName) |
if not inline and not hidden then |
tinsert(tabs, k) |
text[k] = GetOptionsMemberValue("name", v, options, path, appName) |
end |
path[#path] = nil |
end |
end |
del(keySort) |
del(opts) |
return tabs, text |
end |
]] |
local function BuildSelect(group, options, path, appName) |
local groups = new() |
local keySort = new() |
local opts = new() |
BuildSortedOptionsTable(group, keySort, opts, options, path, appName) |
for i = 1, #keySort do |
local k = keySort[i] |
local v = opts[k] |
if v.type == "group" then |
path[#path+1] = k |
local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) |
local hidden = CheckOptionHidden(v, options, path, appName) |
if not inline and not hidden then |
groups[k] = GetOptionsMemberValue("name", v, options, path, appName) |
end |
path[#path] = nil |
end |
end |
del(keySort) |
del(opts) |
return groups |
end |
local function BuildSubGroups(group, tree, options, path, appName) |
local keySort = new() |
local opts = new() |
BuildSortedOptionsTable(group, keySort, opts, options, path, appName) |
for i = 1, #keySort do |
local k = keySort[i] |
local v = opts[k] |
if v.type == "group" then |
path[#path+1] = k |
local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) |
local hidden = CheckOptionHidden(v, options, path, appName) |
if not inline and not hidden then |
local entry = new() |
entry.value = k |
entry.text = GetOptionsMemberValue("name", v, options, path, appName) |
entry.icon = GetOptionsMemberValue("icon", v, options, path, appName) |
entry.disabled = CheckOptionDisabled(v, options, path, appName) |
if not tree.children then tree.children = new() end |
tinsert(tree.children,entry) |
if (v.childGroups or "tree") == "tree" then |
BuildSubGroups(v,entry, options, path, appName) |
end |
end |
path[#path] = nil |
end |
end |
del(keySort) |
del(opts) |
end |
local function BuildGroups(group, options, path, appName, recurse) |
local tree = new() |
local keySort = new() |
local opts = new() |
BuildSortedOptionsTable(group, keySort, opts, options, path, appName) |
for i = 1, #keySort do |
local k = keySort[i] |
local v = opts[k] |
if v.type == "group" then |
path[#path+1] = k |
local inline = pickfirstset(v.dialogInline,v.guiInline,v.inline, false) |
local hidden = CheckOptionHidden(v, options, path, appName) |
if not inline and not hidden then |
local entry = new() |
entry.value = k |
entry.text = GetOptionsMemberValue("name", v, options, path, appName) |
entry.icon = GetOptionsMemberValue("icon", v, options, path, appName) |
entry.disabled = CheckOptionDisabled(v, options, path, appName) |
tinsert(tree,entry) |
if recurse and (v.childGroups or "tree") == "tree" then |
BuildSubGroups(v,entry, options, path, appName) |
end |
end |
path[#path] = nil |
end |
end |
del(keySort) |
del(opts) |
return tree |
end |
local function InjectInfo(control, options, option, path, rootframe, appName) |
local user = control:GetUserDataTable() |
for i = 1, #path do |
user[i] = path[i] |
end |
user.rootframe = rootframe |
user.option = option |
user.options = options |
user.path = copy(path) |
user.appName = appName |
control:SetCallback("OnRelease", CleanUserData) |
control:SetCallback("OnLeave", OptionOnMouseLeave) |
control:SetCallback("OnEnter", OptionOnMouseOver) |
end |
--[[ |
options - root of the options table being fed |
container - widget that controls will be placed in |
rootframe - Frame object the options are in |
path - table with the keys to get to the group being fed |
--]] |
local function FeedOptions(appName, options,container,rootframe,path,group,inline) |
local keySort = new() |
local opts = new() |
BuildSortedOptionsTable(group, keySort, opts, options, path, appName) |
for i = 1, #keySort do |
local k = keySort[i] |
local v = opts[k] |
tinsert(path, k) |
local hidden = CheckOptionHidden(v, options, path, appName) |
local name = GetOptionsMemberValue("name", v, options, path, appName) |
if not hidden then |
if v.type == "group" then |
if inline or pickfirstset(v.dialogInline,v.guiInline,v.inline, false) then |
--Inline group |
local GroupContainer |
if name and name ~= "" then |
GroupContainer = gui:Create("InlineGroup") |
GroupContainer:SetTitle(name or "") |
else |
GroupContainer = gui:Create("SimpleGroup") |
end |
GroupContainer.width = "fill" |
GroupContainer:SetLayout("flow") |
container:AddChild(GroupContainer) |
FeedOptions(appName,options,GroupContainer,rootframe,path,v,true) |
end |
else |
--Control to feed |
local control |
local name = GetOptionsMemberValue("name", v, options, path, appName) |
if v.type == "execute" then |
local imageCoords = GetOptionsMemberValue("imageCoords",v, options, path, appName) |
local image, width, height = GetOptionsMemberValue("image",v, options, path, appName) |
if type(image) == 'string' then |
control = gui:Create("Icon") |
if not width then |
width = GetOptionsMemberValue("imageWidth",v, options, path, appName) |
end |
if not height then |
height = GetOptionsMemberValue("imageHeight",v, options, path, appName) |
end |
if type(imageCoords) == 'table' then |
control:SetImage(image, unpack(imageCoords)) |
else |
control:SetImage(image) |
end |
if type(width) ~= "number" then |
width = 32 |
end |
if type(height) ~= "number" then |
height = 32 |
end |
control:SetImageSize(width, height) |
control:SetLabel(name) |
else |
control = gui:Create("Button") |
control:SetText(name) |
end |
control:SetCallback("OnClick",ActivateControl) |
elseif v.type == "input" then |
local controlType = v.dialogControl or v.control or (v.multiline and "MultiLineEditBox") or "EditBox" |
control = gui:Create(controlType) |
if not control then |
error(("Invalid Custom Control Type - %s"):format(tostring(controlType))) |
end |
if v.multiline then |
local lines = 4 |
if type(v.multiline) == "number" then |
lines = v.multiline |
end |
control:SetHeight(60 + (14*lines)) |
end |
control:SetLabel(name) |
control:SetCallback("OnEnterPressed",ActivateControl) |
local text = GetOptionsMemberValue("get",v, options, path, appName) |
if type(text) ~= "string" then |
text = "" |
end |
control:SetText(text) |
elseif v.type == "toggle" then |
control = gui:Create("CheckBox") |
control:SetLabel(name) |
control:SetTriState(v.tristate) |
local value = GetOptionsMemberValue("get",v, options, path, appName) |
control:SetValue(value) |
control:SetCallback("OnValueChanged",ActivateControl) |
if v.descStyle == "inline" then |
local desc = GetOptionsMemberValue("desc", v, options, path, appName) |
control:SetDescription(desc) |
end |
elseif v.type == "range" then |
control = gui:Create("Slider") |
control:SetLabel(name) |
control:SetSliderValues(v.min or 0,v.max or 100, v.bigStep or v.step or 0) |
control:SetIsPercent(v.isPercent) |
local value = GetOptionsMemberValue("get",v, options, path, appName) |
if type(value) ~= "number" then |
value = 0 |
end |
control:SetValue(value) |
control:SetCallback("OnValueChanged",ActivateSlider) |
control:SetCallback("OnMouseUp",ActivateSlider) |
elseif v.type == "select" then |
local values = GetOptionsMemberValue("values", v, options, path, appName) |
local controlType = v.dialogControl or v.control or "Dropdown" |
control = gui:Create(controlType) |
if not control then |
error(("Invalid Custom Control Type - %s"):format(tostring(controlType))) |
end |
control:SetLabel(name) |
control:SetList(values) |
local value = GetOptionsMemberValue("get",v, options, path, appName) |
if not values[value] then |
value = nil |
end |
control:SetValue(value) |
control:SetCallback("OnValueChanged",ActivateControl) |
elseif v.type == "multiselect" then |
local values = GetOptionsMemberValue("values", v, options, path, appName) |
local disabled = CheckOptionDisabled(v, options, path, appName) |
local controlType = v.dialogControl or v.control |
local valuesort = new() |
if values then |
for value, text in pairs(values) do |
tinsert(valuesort, value) |
end |
end |
table.sort(valuesort) |
if controlType then |
control = gui:Create(controlType) |
if not control then |
error(("Invalid Custom Control Type - %s"):format(tostring(controlType))) |
end |
control:SetMultiselect(true) |
control:SetLabel(name) |
control:SetList(values) |
control:SetDisabled(disabled) |
control:SetCallback("OnValueChanged",ActivateControl) |
control:SetCallback("OnClosed", MultiControlOnClosed) |
local width = GetOptionsMemberValue("width",v,options,path,appName) |
if width == "double" then |
control:SetWidth(width_multiplier * 2) |
elseif width == "half" then |
control:SetWidth(width_multiplier / 2) |
elseif width == "full" then |
control.width = "fill" |
else |
control:SetWidth(width_multiplier) |
end |
--check:SetTriState(v.tristate) |
for i = 1, #valuesort do |
local key = valuesort[i] |
local value = GetOptionsMemberValue("get",v, options, path, appName, key) |
control:SetItemValue(key,value) |
end |
else |
control = gui:Create("InlineGroup") |
control:SetLayout("Flow") |
control:SetTitle(name) |
control.width = "fill" |
control:PauseLayout() |
local width = GetOptionsMemberValue("width",v,options,path,appName) |
for i = 1, #valuesort do |
local value = valuesort[i] |
local text = values[value] |
local check = gui:Create("CheckBox") |
check:SetLabel(text) |
check:SetUserData('value', value) |
check:SetUserData('text', text) |
check:SetDisabled(disabled) |
check:SetTriState(v.tristate) |
check:SetValue(GetOptionsMemberValue("get",v, options, path, appName, value)) |
check:SetCallback("OnValueChanged",ActivateMultiControl) |
InjectInfo(check, options, v, path, rootframe, appName) |
control:AddChild(check) |
if width == "double" then |
check:SetWidth(width_multiplier * 2) |
elseif width == "half" then |
check:SetWidth(width_multiplier / 2) |
elseif width == "full" then |
check.width = "fill" |
else |
check:SetWidth(width_multiplier) |
end |
end |
control:ResumeLayout() |
control:DoLayout() |
end |
del(valuesort) |
elseif v.type == "color" then |
control = gui:Create("ColorPicker") |
control:SetLabel(name) |
control:SetHasAlpha(v.hasAlpha) |
control:SetColor(GetOptionsMemberValue("get",v, options, path, appName)) |
control:SetCallback("OnValueChanged",ActivateControl) |
control:SetCallback("OnValueConfirmed",ActivateControl) |
elseif v.type == "keybinding" then |
control = gui:Create("Keybinding") |
control:SetLabel(name) |
control:SetKey(GetOptionsMemberValue("get",v, options, path, appName)) |
control:SetCallback("OnKeyChanged",ActivateControl) |
elseif v.type == "header" then |
control = gui:Create("Heading") |
control:SetText(name) |
control.width = "fill" |
elseif v.type == "description" then |
control = gui:Create("Label") |
control:SetText(name) |
local fontSize = GetOptionsMemberValue("fontSize",v, options, path, appName) |
if fontSize == "medium" then |
control:SetFontObject(GameFontHighlight) |
elseif fontSize == "large" then |
control:SetFontObject(GameFontHighlightLarge) |
else -- small or invalid |
control:SetFontObject(GameFontHighlightSmall) |
end |
local imageCoords = GetOptionsMemberValue("imageCoords",v, options, path, appName) |
local image, width, height = GetOptionsMemberValue("image",v, options, path, appName) |
if type(image) == 'string' then |
if not width then |
width = GetOptionsMemberValue("imageWidth",v, options, path, appName) |
end |
if not height then |
height = GetOptionsMemberValue("imageHeight",v, options, path, appName) |
end |
if type(imageCoords) == 'table' then |
control:SetImage(image, unpack(imageCoords)) |
else |
control:SetImage(image) |
end |
if type(width) ~= "number" then |
width = 32 |
end |
if type(height) ~= "number" then |
height = 32 |
end |
control:SetImageSize(width, height) |
end |
local width = GetOptionsMemberValue("width",v,options,path,appName) |
control.width = not width and "fill" |
end |
--Common Init |
if control then |
if control.width ~= "fill" then |
local width = GetOptionsMemberValue("width",v,options,path,appName) |
if width == "double" then |
control:SetWidth(width_multiplier * 2) |
elseif width == "half" then |
control:SetWidth(width_multiplier / 2) |
elseif width == "full" then |
control.width = "fill" |
else |
control:SetWidth(width_multiplier) |
end |
end |
if control.SetDisabled then |
local disabled = CheckOptionDisabled(v, options, path, appName) |
control:SetDisabled(disabled) |
end |
InjectInfo(control, options, v, path, rootframe, appName) |
container:AddChild(control) |
end |
end |
end |
tremove(path) |
end |
container:ResumeLayout() |
container:DoLayout() |
del(keySort) |
del(opts) |
end |
local function BuildPath(path, ...) |
for i = 1, select('#',...) do |
tinsert(path, (select(i,...))) |
end |
end |
local function TreeOnButtonEnter(widget, event, uniquevalue, button) |
local user = widget:GetUserDataTable() |
if not user then return end |
local options = user.options |
local option = user.option |
local path = user.path |
local appName = user.appName |
local feedpath = new() |
for i = 1, #path do |
feedpath[i] = path[i] |
end |
BuildPath(feedpath, string.split("\001", uniquevalue)) |
local group = options |
for i = 1, #feedpath do |
if not group then return end |
group = GetSubOption(group, feedpath[i]) |
end |
local name = GetOptionsMemberValue("name", group, options, feedpath, appName) |
local desc = GetOptionsMemberValue("desc", group, options, feedpath, appName) |
GameTooltip:SetOwner(button, "ANCHOR_NONE") |
if widget.type == "TabGroup" then |
GameTooltip:SetPoint("BOTTOM",button,"TOP") |
else |
GameTooltip:SetPoint("LEFT",button,"RIGHT") |
end |
GameTooltip:SetText(name, 1, .82, 0, 1) |
if type(desc) == "string" then |
GameTooltip:AddLine(desc, 1, 1, 1, 1) |
end |
GameTooltip:Show() |
end |
local function TreeOnButtonLeave(widget, event, value, button) |
GameTooltip:Hide() |
end |
local function GroupExists(appName, options, path, uniquevalue) |
if not uniquevalue then return false end |
local feedpath = new() |
local temppath = new() |
for i = 1, #path do |
feedpath[i] = path[i] |
end |
BuildPath(feedpath, string.split("\001", uniquevalue)) |
local group = options |
for i = 1, #feedpath do |
local v = feedpath[i] |
temppath[i] = v |
group = GetSubOption(group, v) |
if not group or group.type ~= "group" or CheckOptionHidden(group, options, temppath, appName) then |
del(feedpath) |
del(temppath) |
return false |
end |
end |
del(feedpath) |
del(temppath) |
return true |
end |
local function GroupSelected(widget, event, uniquevalue) |
local user = widget:GetUserDataTable() |
local options = user.options |
local option = user.option |
local path = user.path |
local rootframe = user.rootframe |
local feedpath = new() |
for i = 1, #path do |
feedpath[i] = path[i] |
end |
BuildPath(feedpath, string.split("\001", uniquevalue)) |
local group = options |
for i = 1, #feedpath do |
group = GetSubOption(group, feedpath[i]) |
end |
widget:ReleaseChildren() |
AceConfigDialog:FeedGroup(user.appName,options,widget,rootframe,feedpath) |
del(feedpath) |
end |
--[[ |
-- INTERNAL -- |
This function will feed one group, and any inline child groups into the given container |
Select Groups will only have the selection control (tree, tabs, dropdown) fed in |
and have a group selected, this event will trigger the feeding of child groups |
Rules: |
If the group is Inline, FeedOptions |
If the group has no child groups, FeedOptions |
If the group is a tab or select group, FeedOptions then add the Group Control |
If the group is a tree group FeedOptions then |
its parent isnt a tree group: then add the tree control containing this and all child tree groups |
if its parent is a tree group, its already a node on a tree |
--]] |
function AceConfigDialog:FeedGroup(appName,options,container,rootframe,path, isRoot) |
local group = options |
--follow the path to get to the curent group |
local inline |
local grouptype, parenttype = options.childGroups, "none" |
--temp path table to pass to callbacks as we traverse the tree |
local temppath = new() |
for i = 1, #path do |
local v = path[i] |
temppath[i] = v |
group = GetSubOption(group, v) |
inline = inline or pickfirstset(v.dialogInline,v.guiInline,v.inline, false) |
parenttype = grouptype |
grouptype = group.childGroups |
end |
del(temppath) |
if not parenttype then |
parenttype = "tree" |
end |
--check if the group has child groups |
local hasChildGroups |
for k, v in pairs(group.args) do |
if v.type == "group" and not pickfirstset(v.dialogInline,v.guiInline,v.inline, false) and not CheckOptionHidden(v, options, path, appName) then |
hasChildGroups = true |
end |
end |
if group.plugins then |
for plugin, t in pairs(group.plugins) do |
for k, v in pairs(t) do |
if v.type == "group" and not pickfirstset(v.dialogInline,v.guiInline,v.inline, false) and not CheckOptionHidden(v, options, path, appName) then |
hasChildGroups = true |
end |
end |
end |
end |
container:SetLayout("flow") |
local scroll |
--Add a scrollframe if we are not going to add a group control, this is the inverse of the conditions for that later on |
if (not (hasChildGroups and not inline)) or (grouptype ~= "tab" and grouptype ~= "select" and (parenttype == "tree" and not isRoot)) then |
if container.type ~= "InlineGroup" then |
scroll = gui:Create("ScrollFrame") |
scroll:SetLayout("flow") |
scroll.width = "fill" |
scroll.height = "fill" |
container:SetLayout("fill") |
container:AddChild(scroll) |
container = scroll |
end |
end |
FeedOptions(appName,options,container,rootframe,path,group,nil) |
if scroll then |
container:PerformLayout() |
local status = self:GetStatusTable(appName, path) |
if not status.scroll then |
status.scroll = {} |
end |
scroll:SetStatusTable(status.scroll) |
end |
if hasChildGroups and not inline then |
if grouptype == "tab" then |
local tab = gui:Create("TabGroup") |
InjectInfo(tab, options, group, path, rootframe, appName) |
tab:SetCallback("OnGroupSelected", GroupSelected) |
tab:SetCallback("OnTabEnter", TreeOnButtonEnter) |
tab:SetCallback("OnTabLeave", TreeOnButtonLeave) |
local status = AceConfigDialog:GetStatusTable(appName, path) |
if not status.groups then |
status.groups = {} |
end |
tab:SetStatusTable(status.groups) |
tab.width = "fill" |
tab.height = "fill" |
local tabs = BuildGroups(group, options, path, appName) |
tab:SetTabs(tabs) |
tab:SetUserData("tablist", tabs) |
for i = 1, #tabs do |
local entry = tabs[i] |
if not entry.disabled then |
tab:SelectTab((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value) |
break |
end |
end |
container:AddChild(tab) |
elseif grouptype == "select" then |
local select = gui:Create("DropdownGroup") |
InjectInfo(select, options, group, path, rootframe, appName) |
select:SetCallback("OnGroupSelected", GroupSelected) |
local status = AceConfigDialog:GetStatusTable(appName, path) |
if not status.groups then |
status.groups = {} |
end |
select:SetStatusTable(status.groups) |
local grouplist = BuildSelect(group, options, path, appName) |
select:SetGroupList(grouplist) |
select:SetUserData("grouplist", grouplist) |
local firstgroup |
for k, v in pairs(grouplist) do |
if not firstgroup or k < firstgroup then |
firstgroup = k |
end |
end |
if firstgroup then |
select:SetGroup( (GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or firstgroup) |
end |
select.width = "fill" |
select.height = "fill" |
container:AddChild(select) |
--assume tree group by default |
--if parenttype is tree then this group is already a node on that tree |
elseif (parenttype ~= "tree") or isRoot then |
local tree = gui:Create("TreeGroup") |
InjectInfo(tree, options, group, path, rootframe, appName) |
tree:EnableButtonTooltips(false) |
tree.width = "fill" |
tree.height = "fill" |
tree:SetCallback("OnGroupSelected", GroupSelected) |
tree:SetCallback("OnButtonEnter", TreeOnButtonEnter) |
tree:SetCallback("OnButtonLeave", TreeOnButtonLeave) |
local status = AceConfigDialog:GetStatusTable(appName, path) |
if not status.groups then |
status.groups = {} |
end |
local treedefinition = BuildGroups(group, options, path, appName, true) |
tree:SetStatusTable(status.groups) |
tree:SetTree(treedefinition) |
tree:SetUserData("tree",treedefinition) |
for i = 1, #treedefinition do |
local entry = treedefinition[i] |
if not entry.disabled then |
tree:SelectByValue((GroupExists(appName, options, path,status.groups.selected) and status.groups.selected) or entry.value) |
break |
end |
end |
container:AddChild(tree) |
end |
end |
end |
local old_CloseSpecialWindows |
local function RefreshOnUpdate(this) |
for appName in pairs(this.closing) do |
if AceConfigDialog.OpenFrames[appName] then |
AceConfigDialog.OpenFrames[appName]:Hide() |
end |
if AceConfigDialog.BlizOptions and AceConfigDialog.BlizOptions[appName] then |
local widget = AceConfigDialog.BlizOptions[appName] |
if not widget:IsVisible() then |
widget:ReleaseChildren() |
end |
end |
this.closing[appName] = nil |
end |
if this.closeAll then |
for k, v in pairs(AceConfigDialog.OpenFrames) do |
v:Hide() |
end |
this.closeAll = nil |
end |
for appName in pairs(this.apps) do |
if AceConfigDialog.OpenFrames[appName] then |
local user = AceConfigDialog.OpenFrames[appName]:GetUserDataTable() |
AceConfigDialog:Open(appName, user.basepath and unpack(user.basepath)) |
end |
if AceConfigDialog.BlizOptions and AceConfigDialog.BlizOptions[appName] then |
local widget = AceConfigDialog.BlizOptions[appName] |
local user = widget:GetUserDataTable() |
if widget:IsVisible() then |
AceConfigDialog:Open(widget:GetUserData('appName'), widget, user.basepath and unpack(user.basepath)) |
end |
end |
this.apps[appName] = nil |
end |
this:SetScript("OnUpdate", nil) |
end |
--- Close all open options windows |
function AceConfigDialog:CloseAll() |
AceConfigDialog.frame.closeAll = true |
AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate) |
if next(self.OpenFrames) then |
return true |
end |
end |
--- Close a specific options window. |
-- @param appName The application name as given to `:RegisterOptionsTable()` |
function AceConfigDialog:Close(appName) |
if self.OpenFrames[appName] then |
AceConfigDialog.frame.closing[appName] = true |
AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate) |
return true |
end |
end |
-- Internal -- Called by AceConfigRegistry |
function AceConfigDialog:ConfigTableChanged(event, appName) |
AceConfigDialog.frame.apps[appName] = true |
AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate) |
end |
reg.RegisterCallback(AceConfigDialog, "ConfigTableChange", "ConfigTableChanged") |
--- Sets the default size of the options window for a specific application. |
-- @param appName The application name as given to `:RegisterOptionsTable()` |
-- @param width The default width |
-- @param height The default height |
function AceConfigDialog:SetDefaultSize(appName, width, height) |
local status = AceConfigDialog:GetStatusTable(appName) |
if type(width) == "number" and type(height) == "number" then |
status.width = width |
status.height = height |
end |
end |
--- Open an option window at the specified path (if any). |
-- This function can optionally feed the group into a pre-created container |
-- instead of creating a new container frame. |
-- @paramsig appName [, container][, ...] |
-- @param appName The application name as given to `:RegisterOptionsTable()` |
-- @param container An optional container frame to feed the options into |
-- @param ... The path to open after creating the options window (see `:SelectGroup` for details) |
function AceConfigDialog:Open(appName, container, ...) |
if not old_CloseSpecialWindows then |
old_CloseSpecialWindows = CloseSpecialWindows |
CloseSpecialWindows = function() |
local found = old_CloseSpecialWindows() |
return self:CloseAll() or found |
end |
end |
local app = reg:GetOptionsTable(appName) |
if not app then |
error(("%s isn't registed with AceConfigRegistry, unable to open config"):format(appName), 2) |
end |
local options = app("dialog", MAJOR) |
local f |
local path = new() |
local name = GetOptionsMemberValue("name", options, options, path, appName) |
--If an optional path is specified add it to the path table before feeding the options |
--as container is optional as well it may contain the first element of the path |
if type(container) == "string" then |
tinsert(path, container) |
container = nil |
end |
for n = 1, select('#',...) do |
tinsert(path, (select(n, ...))) |
end |
--if a container is given feed into that |
if container then |
f = container |
f:ReleaseChildren() |
f:SetUserData('appName', appName) |
f:SetUserData('iscustom', true) |
if #path > 0 then |
f:SetUserData('basepath', copy(path)) |
end |
local status = AceConfigDialog:GetStatusTable(appName) |
if not status.width then |
status.width = 700 |
end |
if not status.height then |
status.height = 500 |
end |
if f.SetStatusTable then |
f:SetStatusTable(status) |
end |
if f.SetTitle then |
f:SetTitle(name or "") |
end |
else |
if not self.OpenFrames[appName] then |
f = gui:Create("Frame") |
self.OpenFrames[appName] = f |
else |
f = self.OpenFrames[appName] |
end |
f:ReleaseChildren() |
f:SetCallback("OnClose", FrameOnClose) |
f:SetUserData('appName', appName) |
if #path > 0 then |
f:SetUserData('basepath', copy(path)) |
end |
f:SetTitle(name or "") |
local status = AceConfigDialog:GetStatusTable(appName) |
f:SetStatusTable(status) |
end |
self:FeedGroup(appName,options,f,f,path,true) |
if f.Show then |
f:Show() |
end |
del(path) |
end |
AceConfigDialog.BlizOptions = AceConfigDialog.BlizOptions or {} |
local function FeedToBlizPanel(widget, event) |
local path = widget:GetUserData('path') |
AceConfigDialog:Open(widget:GetUserData('appName'), widget, path and unpack(path)) |
end |
local function ClearBlizPanel(widget, event) |
local appName = widget:GetUserData('appName') |
AceConfigDialog.frame.closing[appName] = true |
AceConfigDialog.frame:SetScript("OnUpdate", RefreshOnUpdate) |
end |
--- Add an option table into the Blizzard Interface Options panel. |
-- You can optionally supply a descriptive name to use and a parent frame to use, |
-- as well as a path in the options table.\\ |
-- If no name is specified, the appName will be used instead. |
-- |
-- If you specify a proper `parent` (by name), the interface options will generate a |
-- tree layout. Note that only one level of children is supported, so the parent always |
-- has to be a head-level note. |
-- |
-- This function returns a reference to the container frame registered with the Interface |
-- Options. You can use this reference to open the options with the API function |
-- `InterfaceOptionsFrame_OpenToCategory`. |
-- @param appName The application name as given to `:RegisterOptionsTable()` |
-- @param name A descriptive name to display in the options tree (defaults to appName) |
-- @param parent The parent to use in the interface options tree. |
-- @param ... The path in the options table to feed into the interface options panel. |
-- @return The reference to the frame registered into the Interface Options. |
function AceConfigDialog:AddToBlizOptions(appName, name, parent, ...) |
local BlizOptions = AceConfigDialog.BlizOptions |
local key = appName |
for n = 1, select('#', ...) do |
key = key..'\001'..select(n, ...) |
end |
if not BlizOptions[key] then |
local group = gui:Create("BlizOptionsGroup") |
BlizOptions[key] = group |
group:SetName(name or appName, parent) |
group:SetTitle(name or appName) |
group:SetUserData('appName', appName) |
if select('#', ...) > 0 then |
local path = {} |
for n = 1, select('#',...) do |
tinsert(path, (select(n, ...))) |
end |
group:SetUserData('path', path) |
end |
group:SetCallback("OnShow", FeedToBlizPanel) |
group:SetCallback("OnHide", ClearBlizPanel) |
InterfaceOptions_AddCategory(group.frame) |
return group.frame |
else |
error(("%s has already been added to the Blizzard Options Window with the given path"):format(appName), 2) |
end |
end |
<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> |
--- **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 840 2009-09-10 10:24:32Z nevcairiel $ |
local ACEDB_MAJOR, ACEDB_MINOR = "AceDB-3.0", 17 |
local AceDB, oldminor = LibStub:NewLibrary(ACEDB_MAJOR, ACEDB_MINOR) |
if not AceDB then return end -- No upgrade needed |
local _G = getfenv(0) |
local type = type |
local pairs, next = pairs, next |
local rawget, rawset = rawget, rawset |
local setmetatable = setmetatable |
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 |
-- Actual database initialization function |
local function initdb(sv, defaults, defaultProfile, olddb, parent) |
-- Generate the database keys for each section |
-- Make a container for profile keys |
if not sv.profileKeys then sv.profileKeys = {} end |
-- map "true" to our "Default" profile |
if defaultProfile == true then defaultProfile = "Default" end |
local profileKey |
if not parent then |
-- Try to get the profile selected from the char db |
profileKey = sv.profileKeys[charKey] or defaultProfile or charKey |
else |
-- Use the profile of the parents DB |
profileKey = parent.keys.profile or defaultProfile or charKey |
end |
sv.profileKeys[charKey] = profileKey |
-- 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, |
["profile"] = profileKey, |
["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 |
local function logoutHandler(frame, event) |
if event == "PLAYER_LOGOUT" then |
for db in pairs(AceDB.db_registry) do |
db.callbacks:Fire("OnDatabaseShutdown", db) |
for section, key in pairs(db.keys) do |
if db.defaults and db.defaults[section] and rawget(db, section) then |
removeDefaults(db[section], db.defaults[section]) |
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 |
self.sv.profileKeys[charKey] = name |
-- 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.sv.profiles, name) and not silent then |
error("Cannot delete profile '" .. name .. "'. It does not exist.", 2) |
end |
self.sv.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 |
-- 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.sv.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) |
local profile = self.profile |
local source = self.sv.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 |
function DBObjectLib:ResetProfile(noChildren) |
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) |
end |
end |
-- Callback: OnProfileReset, database |
self.callbacks:Fire("OnProfileReset", self) |
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 = {} |
setglobal(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 |
-- A library to compute Gear Points for items as described in |
-- http://code.google.com/p/epgp/wiki/GearPoints |
local MAJOR_VERSION = "LibGearPoints-1.0" |
local MINOR_VERSION = tonumber(("$Revision: 1023 $"):match("%d+")) or 0 |
local lib, oldMinor = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION) |
if not lib then return end |
local Debug = LibStub("LibDebug-1.0") |
-- This is the high price equipslot multiplier. |
local EQUIPSLOT_MULTIPLIER_1 = { |
INVTYPE_HEAD = 1, |
INVTYPE_NECK = 0.5, |
INVTYPE_SHOULDER = 0.75, |
INVTYPE_CHEST = 1, |
INVTYPE_ROBE = 1, |
INVTYPE_WAIST = 0.75, |
INVTYPE_LEGS = 1, |
INVTYPE_FEET = 0.75, |
INVTYPE_WRIST = 0.5, |
INVTYPE_HAND = 0.75, |
INVTYPE_FINGER = 0.5, |
INVTYPE_TRINKET = 0.75, |
INVTYPE_CLOAK = 0.5, |
INVTYPE_WEAPON = 1.5, |
INVTYPE_SHIELD = 1.5, |
INVTYPE_2HWEAPON = 2, |
INVTYPE_WEAPONMAINHAND = 1.5, |
INVTYPE_WEAPONOFFHAND = 0.5, |
INVTYPE_HOLDABLE = 0.5, |
INVTYPE_RANGED = 1.5, |
INVTYPE_RANGEDRIGHT = 1.5, |
INVTYPE_THROWN = 0.5, |
INVTYPE_RELIC = 0.5, |
-- Hack for Tier 9 25M heroic tokens. |
INVTYPE_CUSTOM_MULTISLOT_TIER = 0.9, |
} |
-- This is the low price equipslot multiplier (off hand weapons, non |
-- tanking shields). |
local EQUIPSLOT_MULTIPLIER_2 = { |
INVTYPE_WEAPON = 0.5, |
INVTYPE_SHIELD = 0.5, |
INVTYPE_2HWEAPON = 1, |
INVTYPE_RANGED = 0.5, |
INVTYPE_RANGEDRIGHT = 0.5, |
} |
--Used to display GP values directly on tier tokens |
local CUSTOM_ITEM_DATA = { |
-- Tier 4 |
[29753] = { 4, 120, "INVTYPE_CHEST" }, |
[29754] = { 4, 120, "INVTYPE_CHEST" }, |
[29755] = { 4, 120, "INVTYPE_CHEST" }, |
[29756] = { 4, 120, "INVTYPE_HAND" }, |
[29757] = { 4, 120, "INVTYPE_HAND" }, |
[29758] = { 4, 120, "INVTYPE_HAND" }, |
[29759] = { 4, 120, "INVTYPE_HEAD" }, |
[29760] = { 4, 120, "INVTYPE_HEAD" }, |
[29761] = { 4, 120, "INVTYPE_HEAD" }, |
[29762] = { 4, 120, "INVTYPE_SHOULDER" }, |
[29763] = { 4, 120, "INVTYPE_SHOULDER" }, |
[29764] = { 4, 120, "INVTYPE_SHOULDER" }, |
[29765] = { 4, 120, "INVTYPE_LEGS" }, |
[29766] = { 4, 120, "INVTYPE_LEGS" }, |
[29767] = { 4, 120, "INVTYPE_LEGS" }, |
-- Tier 5 |
[30236] = { 4, 133, "INVTYPE_CHEST" }, |
[30237] = { 4, 133, "INVTYPE_CHEST" }, |
[30238] = { 4, 133, "INVTYPE_CHEST" }, |
[30239] = { 4, 133, "INVTYPE_HAND" }, |
[30240] = { 4, 133, "INVTYPE_HAND" }, |
[30241] = { 4, 133, "INVTYPE_HAND" }, |
[30242] = { 4, 133, "INVTYPE_HEAD" }, |
[30243] = { 4, 133, "INVTYPE_HEAD" }, |
[30244] = { 4, 133, "INVTYPE_HEAD" }, |
[30245] = { 4, 133, "INVTYPE_LEGS" }, |
[30246] = { 4, 133, "INVTYPE_LEGS" }, |
[30247] = { 4, 133, "INVTYPE_LEGS" }, |
[30248] = { 4, 133, "INVTYPE_SHOULDER" }, |
[30249] = { 4, 133, "INVTYPE_SHOULDER" }, |
[30250] = { 4, 133, "INVTYPE_SHOULDER" }, |
-- Tier 5 - BoE recipes - BoP crafts |
[30282] = { 4, 128, "INVTYPE_BOOTS" }, |
[30283] = { 4, 128, "INVTYPE_BOOTS" }, |
[30305] = { 4, 128, "INVTYPE_BOOTS" }, |
[30306] = { 4, 128, "INVTYPE_BOOTS" }, |
[30307] = { 4, 128, "INVTYPE_BOOTS" }, |
[30308] = { 4, 128, "INVTYPE_BOOTS" }, |
[30323] = { 4, 128, "INVTYPE_BOOTS" }, |
[30324] = { 4, 128, "INVTYPE_BOOTS" }, |
-- Tier 6 |
[31089] = { 4, 146, "INVTYPE_CHEST" }, |
[31090] = { 4, 146, "INVTYPE_CHEST" }, |
[31091] = { 4, 146, "INVTYPE_CHEST" }, |
[31092] = { 4, 146, "INVTYPE_HAND" }, |
[31093] = { 4, 146, "INVTYPE_HAND" }, |
[31094] = { 4, 146, "INVTYPE_HAND" }, |
[31095] = { 4, 146, "INVTYPE_HEAD" }, |
[31096] = { 4, 146, "INVTYPE_HEAD" }, |
[31097] = { 4, 146, "INVTYPE_HEAD" }, |
[31098] = { 4, 146, "INVTYPE_LEGS" }, |
[31099] = { 4, 146, "INVTYPE_LEGS" }, |
[31100] = { 4, 146, "INVTYPE_LEGS" }, |
[31101] = { 4, 146, "INVTYPE_SHOULDER" }, |
[31102] = { 4, 146, "INVTYPE_SHOULDER" }, |
[31103] = { 4, 146, "INVTYPE_SHOULDER" }, |
[34848] = { 4, 154, "INVTYPE_WRIST" }, |
[34851] = { 4, 154, "INVTYPE_WRIST" }, |
[34852] = { 4, 154, "INVTYPE_WRIST" }, |
[34853] = { 4, 154, "INVTYPE_WAIST" }, |
[34854] = { 4, 154, "INVTYPE_WAIST" }, |
[34855] = { 4, 154, "INVTYPE_WAIST" }, |
[34856] = { 4, 154, "INVTYPE_FEET" }, |
[34857] = { 4, 154, "INVTYPE_FEET" }, |
[34858] = { 4, 154, "INVTYPE_FEET" }, |
-- Tier 6 - BoE recipes - BoP crafts |
[32737] = { 4, 141, "INVTYPE_SHOULDER" }, |
[32739] = { 4, 141, "INVTYPE_SHOULDER" }, |
[32745] = { 4, 141, "INVTYPE_SHOULDER" }, |
[32747] = { 4, 141, "INVTYPE_SHOULDER" }, |
[32749] = { 4, 141, "INVTYPE_SHOULDER" }, |
[32751] = { 4, 141, "INVTYPE_SHOULDER" }, |
[32753] = { 4, 141, "INVTYPE_SHOULDER" }, |
[32755] = { 4, 141, "INVTYPE_SHOULDER" }, |
-- Magtheridon's Head |
[32385] = { 4, 125, "INVTYPE_FINGER" }, |
[32386] = { 4, 125, "INVTYPE_FINGER" }, |
-- Kael'thas' Sphere |
[32405] = { 4, 138, "INVTYPE_NECK" }, |
-- T7 |
[40610] = { 4, 200, "INVTYPE_CHEST" }, |
[40611] = { 4, 200, "INVTYPE_CHEST" }, |
[40612] = { 4, 200, "INVTYPE_CHEST" }, |
[40613] = { 4, 200, "INVTYPE_HAND" }, |
[40614] = { 4, 200, "INVTYPE_HAND" }, |
[40615] = { 4, 200, "INVTYPE_HAND" }, |
[40616] = { 4, 200, "INVTYPE_HEAD" }, |
[40617] = { 4, 200, "INVTYPE_HEAD" }, |
[40618] = { 4, 200, "INVTYPE_HEAD" }, |
[40619] = { 4, 200, "INVTYPE_LEGS" }, |
[40620] = { 4, 200, "INVTYPE_LEGS" }, |
[40621] = { 4, 200, "INVTYPE_LEGS" }, |
[40622] = { 4, 200, "INVTYPE_SHOULDER" }, |
[40623] = { 4, 200, "INVTYPE_SHOULDER" }, |
[40624] = { 4, 200, "INVTYPE_SHOULDER" }, |
-- T7 (heroic) |
[40625] = { 4, 213, "INVTYPE_CHEST" }, |
[40626] = { 4, 213, "INVTYPE_CHEST" }, |
[40627] = { 4, 213, "INVTYPE_CHEST" }, |
[40628] = { 4, 213, "INVTYPE_HAND" }, |
[40629] = { 4, 213, "INVTYPE_HAND" }, |
[40630] = { 4, 213, "INVTYPE_HAND" }, |
[40631] = { 4, 213, "INVTYPE_HEAD" }, |
[40632] = { 4, 213, "INVTYPE_HEAD" }, |
[40633] = { 4, 213, "INVTYPE_HEAD" }, |
[40634] = { 4, 213, "INVTYPE_LEGS" }, |
[40635] = { 4, 213, "INVTYPE_LEGS" }, |
[40636] = { 4, 213, "INVTYPE_LEGS" }, |
[40637] = { 4, 213, "INVTYPE_SHOULDER" }, |
[40638] = { 4, 213, "INVTYPE_SHOULDER" }, |
[40639] = { 4, 213, "INVTYPE_SHOULDER" }, |
-- Key to the Focusing Iris |
[44569] = { 4, 213, "INVTYPE_NECK" }, |
[44577] = { 4, 226, "INVTYPE_NECK" }, |
-- T8 |
[45635] = { 4, 219, "INVTYPE_CHEST" }, |
[45636] = { 4, 219, "INVTYPE_CHEST" }, |
[45637] = { 4, 219, "INVTYPE_CHEST" }, |
[45647] = { 4, 219, "INVTYPE_HEAD" }, |
[45648] = { 4, 219, "INVTYPE_HEAD" }, |
[45649] = { 4, 219, "INVTYPE_HEAD" }, |
[45644] = { 4, 219, "INVTYPE_HAND" }, |
[45645] = { 4, 219, "INVTYPE_HAND" }, |
[45646] = { 4, 219, "INVTYPE_HAND" }, |
[45650] = { 4, 219, "INVTYPE_LEGS" }, |
[45651] = { 4, 219, "INVTYPE_LEGS" }, |
[45652] = { 4, 219, "INVTYPE_LEGS" }, |
[45659] = { 4, 219, "INVTYPE_SHOULDER" }, |
[45660] = { 4, 219, "INVTYPE_SHOULDER" }, |
[45661] = { 4, 219, "INVTYPE_SHOULDER" }, |
-- T8 (heroic) |
[45632] = { 4, 226, "INVTYPE_CHEST" }, |
[45633] = { 4, 226, "INVTYPE_CHEST" }, |
[45634] = { 4, 226, "INVTYPE_CHEST" }, |
[45638] = { 4, 226, "INVTYPE_HEAD" }, |
[45639] = { 4, 226, "INVTYPE_HEAD" }, |
[45640] = { 4, 226, "INVTYPE_HEAD" }, |
[45641] = { 4, 226, "INVTYPE_HAND" }, |
[45642] = { 4, 226, "INVTYPE_HAND" }, |
[45643] = { 4, 226, "INVTYPE_HAND" }, |
[45653] = { 4, 226, "INVTYPE_LEGS" }, |
[45654] = { 4, 226, "INVTYPE_LEGS" }, |
[45655] = { 4, 226, "INVTYPE_LEGS" }, |
[45656] = { 4, 226, "INVTYPE_SHOULDER" }, |
[45657] = { 4, 226, "INVTYPE_SHOULDER" }, |
[45658] = { 4, 226, "INVTYPE_SHOULDER" }, |
-- Reply Code Alpha |
[46052] = { 4, 226, "INVTYPE_RING" }, |
[46053] = { 4, 239, "INVTYPE_RING" }, |
-- T9.245 (10M heroic/25M) |
[47242] = { 4, 245, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
-- T9.258 (25M heroic) |
[47557] = { 4, 258, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
[47558] = { 4, 258, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
[47559] = { 4, 258, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
-- T10.264 (10M heroic/25M) |
[52025] = { 4, 264, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
[52026] = { 4, 264, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
[52027] = { 4, 264, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
-- T10.279 (25M heroic) |
[52028] = { 4, 279, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
[52029] = { 4, 279, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
[52030] = { 4, 279, "INVTYPE_CUSTOM_MULTISLOT_TIER" }, |
} |
-- The default quality threshold: |
-- 0 - Poor |
-- 1 - Uncommon |
-- 2 - Common |
-- 3 - Rare |
-- 4 - Epic |
-- 5 - Legendary |
-- 6 - Artifact |
local quality_threshold = 4 |
local recent_items_queue = {} |
local recent_items_map = {} |
local function UpdateRecentLoot(itemLink) |
if recent_items_map[itemLink] then return end |
Debug("Adding %s to recent items", itemLink) |
table.insert(recent_items_queue, 1, itemLink) |
recent_items_map[itemLink] = true |
if #recent_items_queue > 15 then |
local itemLink = table.remove(recent_items_queue) |
Debug("Removing %s from recent items", itemLink) |
recent_items_map[itemLink] = nil |
end |
end |
function lib:GetNumRecentItems() |
return #recent_items_queue |
end |
function lib:GetRecentItemLink(i) |
return recent_items_queue[i] |
end |
--- Return the currently set quality threshold. |
function lib:GetQualityThreshold() |
return quality_threshold |
end |
--- Set the minimum quality threshold. |
-- @param itemQuality Lowest allowed item quality. |
function lib:SetQualityThreshold(itemQuality) |
itemQuality = itemQuality and tonumber(itemQuality) |
if not itemQuality or itemQuality > 6 or itemQuality < 0 then |
return error("Usage: SetQualityThreshold(itemQuality): 'itemQuality' - number [0,6].", 3) |
end |
quality_threshold = itemQuality |
end |
function lib:GetValue(item) |
if not item then return end |
local _, itemLink, rarity, level, _, _, _, _, equipLoc = GetItemInfo(item) |
if not itemLink then return end |
-- Get the item ID to check against known token IDs |
local itemID = itemLink:match("item:(%d+)") |
if not itemID then return end |
itemID = tonumber(itemID) |
-- Check to see if there is custom data for this item ID |
if CUSTOM_ITEM_DATA[itemID] then |
rarity, level, equipLoc = unpack(CUSTOM_ITEM_DATA[itemID]) |
end |
-- Is the item above our minimum threshold? |
if not rarity or rarity < quality_threshold then |
return nil, nil, level, rarity, equipLoc |
end |
UpdateRecentLoot(itemLink) |
local slot_multiplier1 = EQUIPSLOT_MULTIPLIER_1[equipLoc] |
local slot_multiplier2 = EQUIPSLOT_MULTIPLIER_2[equipLoc] |
if not slot_multiplier1 then |
return nil, nil, level, rarity, equipLoc |
end |
local gp_base = 0.483 * 2 ^ (level/26 + (rarity - 4)) |
local high = math.floor(gp_base * slot_multiplier1) |
local low = slot_multiplier2 and math.floor(gp_base * slot_multiplier2) or nil |
return high, low, level, rarity, equipLoc |
end |
-- |
-- 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! :-) |
-- |
local CTL_VERSION = 21 |
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 |
----------------------------------------------------------------------- |
-- 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, which also happens to be a ring member |
ChatThrottleLib.PipeBin = nil -- pre-v19, drastically different |
local PipeBin = setmetatable({}, {__mode="k"}) |
local function DelPipe(pipe) |
for i = #pipe, 1, -1 do |
pipe[i] = nil |
end |
pipe.prev = nil |
pipe.next = nil |
PipeBin[pipe] = true |
end |
local function NewPipe() |
local pipe = next(PipeBin) |
if pipe then |
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 |
function ChatThrottleLib:Despool(Prio) |
local ring = Prio.Ring |
while ring.pos and Prio.avail > ring.pos[1].nSize do |
local msg = table_remove(Prio.Ring.pos, 1) |
if not Prio.Ring.pos[1] then |
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 |
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) |
if msg.callbackFn then |
msg.callbackFn (msg.callbackArg) |
end |
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) |
end |
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 = prefix:len() + 1 + text:len(); |
if nSize>255 then |
error("ChatThrottleLib:SendAddonMessage(): prefix + message length cannot exceed 254 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.SendAddonMessage(prefix, text, chattype, target) |
bMyTraffic = false |
self.Prio[prio].nTotalSent = self.Prio[prio].nTotalSent + nSize |
if callbackFn then |
callbackFn (callbackArg) |
end |
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 |
]] |
<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> |
--- **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 823 2009-08-11 12:29:21Z mikk $ |
--[[ 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", 6 |
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") |
local type = type |
local strsub = string.sub |
local strfind = string.find |
local tinsert = table.insert |
local tconcat = table.concat |
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" |
AceComm.multipart_origprefixes = AceComm.multipart_origprefixes or {} -- e.g. "Prefix\001"="Prefix", "Prefix\002"="Prefix" |
AceComm.multipart_reassemblers = AceComm.multipart_reassemblers or {} -- e.g. "Prefix\001"="OnReceiveMultipartFirst" |
-- 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) |
-- @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 |
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 |
if strfind(prefix, "[\001-\009]") then |
if strfind(prefix, "[\001-\003]") then |
error("SendCommMessage: Characters \\001--\\003 in prefix are reserved for AceComm metadata", 2) |
elseif not warnedPrefix then |
-- I have some ideas about future extensions that require more control characters /mikk, 20090808 |
geterrorhandler()("SendCommMessage: Heads-up developers: Characters \\004--\\009 in prefix are reserved for AceComm future extension") |
warnedPrefix = true |
end |
end |
local textlen = #text |
local maxtextlen = 254 - #prefix -- 254 is the max length of prefix + text that can be sent in one message |
local queueName = prefix..distribution..(target or "") |
local ctlCallback = nil |
if callbackFn then |
ctlCallback = function(sent) |
return callbackFn(callbackArg, sent, textlen) |
end |
end |
if 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 |
-- 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 |
local prefix2 = prefix..MSG_MULTI_NEXT |
while pos+maxtextlen <= textlen do |
chunk = strsub(text, pos, pos+maxtextlen-1) |
CTL:SendAddonMessage(prio, prefix2, 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 |
-- ensure that 'prefix to watch' table is consistent with registered |
-- callbacks |
AceComm.__prefixes = {} |
AceComm.callbacks = CallbackHandler:New(AceComm, |
"_RegisterComm", |
"UnregisterComm", |
"UnregisterAllComm") |
end |
function AceComm.callbacks:OnUsed(target, prefix) |
AceComm.multipart_origprefixes[prefix..MSG_MULTI_FIRST] = prefix |
AceComm.multipart_reassemblers[prefix..MSG_MULTI_FIRST] = "OnReceiveMultipartFirst" |
AceComm.multipart_origprefixes[prefix..MSG_MULTI_NEXT] = prefix |
AceComm.multipart_reassemblers[prefix..MSG_MULTI_NEXT] = "OnReceiveMultipartNext" |
AceComm.multipart_origprefixes[prefix..MSG_MULTI_LAST] = prefix |
AceComm.multipart_reassemblers[prefix..MSG_MULTI_LAST] = "OnReceiveMultipartLast" |
end |
function AceComm.callbacks:OnUnused(target, prefix) |
AceComm.multipart_origprefixes[prefix..MSG_MULTI_FIRST] = nil |
AceComm.multipart_reassemblers[prefix..MSG_MULTI_FIRST] = nil |
AceComm.multipart_origprefixes[prefix..MSG_MULTI_NEXT] = nil |
AceComm.multipart_reassemblers[prefix..MSG_MULTI_NEXT] = nil |
AceComm.multipart_origprefixes[prefix..MSG_MULTI_LAST] = nil |
AceComm.multipart_reassemblers[prefix..MSG_MULTI_LAST] = nil |
end |
local function OnEvent(this, event, ...) |
if event == "CHAT_MSG_ADDON" then |
local prefix,message,distribution,sender = ... |
local reassemblername = AceComm.multipart_reassemblers[prefix] |
if reassemblername then |
-- multipart: reassemble |
local aceCommReassemblerFunc = AceComm[reassemblername] |
local origprefix = AceComm.multipart_origprefixes[prefix] |
aceCommReassemblerFunc(AceComm, origprefix, message, distribution, sender) |
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 |