--[[ Name: EasyDND - AntiParasites / LibDataBroker LibDBIcon-1.0 DewdropLib Description: This file handles Broker used for displaying a minimap icon with LibDBIcon-1.0 this add support to all bar mods and/or minimap with minimal spared codes Thanks Rabbit and Tekkub it saves so much! Version: 30100.$Revision: 81 $ $Date: 2009-04-27 10:54:30 +0000 (Mon, 27 Apr 2009) $ Author(s): Merah (ad@heapoverflow.com) Playing: Mera,Merae,Merah & FathisUles on EU FR-La Croisade Ecarlate ;) Website1: http://www.wowinterface.com/downloads/info8717-EasyDND.html Website2: http://wow.curse.com/downloads/wow-addons/details/easydnd.aspx SVN: svn://svn.wowinterface.com/EasyDND-211 Description: Automatically deny guild, trade, duel, party invitations, guild petitions, remove sounds and forced AH, mail windows closure, automatically activate DND or AFK modes in various situations, etc.. License: LGPL 2.1 ]] local MINOR_VERSION = tonumber(("$Revision: 81 $"):match("%d+")) if MINOR_VERSION > _G.EasyDND_MINOR_VERSION then _G.EasyDND_MINOR_VERSION = MINOR_VERSION end if not LibStub then return end local LDB, LDB_EV = LibStub:GetLibrary("LibDataBroker-1.1"), LibStub("AceEvent-3.0") local _, L, DEW, ICO = EasyDND, LibStub("AceLocale-3.0"):GetLocale("EasyDND"), LibStub("Dewdrop-2.0", true), LibStub("LibDBIcon-1.0", true) if not ( LDB or _ or L ) then return end local ICONOFF = "Interface\\AddOns\\EasyDND\\icons\\dndoff" local ICONON = "Interface\\AddOns\\EasyDND\\icons\\dndon" local function CheckLDBCounter() if _.db.profile.showcounter then if _.db.profile.anti_counter then return ":".._.db.profile.anti_counter end end return "" end local function CheckLDBFlag() if UnitIsDND("player") then return "[" .. L["DND"] .. "]"..CheckLDBCounter() elseif UnitIsAFK("player") then return "[" .. L["AFK"] .. "]"..CheckLDBCounter() end return "[---]"..CheckLDBCounter() end local function CheckStatus(a, b) local on, off = "|cff33ff33ON|r", "|cffff0000OFF|r" if not b and not _.db.profile.activated then return off end if a then return on end return off end local function ToggleMinimap() if _.db.profile.showminimap then if ICO then ICO:Show("EasyDND") else if _.db.profile.showarnings then _:Print("|cff7e7e7e"..L["Minimap icon disabled, install"].." LibDBIcon-1.0 "..L["to activate this feature"].."|r") end end else if ICO then ICO:Hide("EasyDND") end end end local function AdjustDewdropPosition(a) local dewdrop = _G["Dewdrop20Level1"] or false if dewdrop and a then local point = dewdrop:GetPoint() or "none" if point == "TOPRIGHT" then dewdrop:ClearAllPoints() dewdrop:SetPoint("TOPRIGHT", a, "BOTTOMLEFT", 0, 0) elseif point == "TOPLEFT" then dewdrop:ClearAllPoints() dewdrop:SetPoint("TOPLEFT", a, "BOTTOMRIGHT", 0, 0) elseif point == "BOTTOMRIGHT" then dewdrop:ClearAllPoints() dewdrop:SetPoint("BOTTOMRIGHT", a, "TOPLEFT", 0, 0) elseif point == "BOTTOMLEFT" then dewdrop:ClearAllPoints() dewdrop:SetPoint("BOTTOMLEFT", a, "TOPRIGHT", 0, 0) end end end local sig = "[AntiParasites] " local function ToggleDewdrop(a) if not DEW then if _.db.profile.showarnings then _:Print("|cff7e7e7e"..L["Quick menu disabled, install"].." DewdropLib "..L["to activate this feature"]) end _.ToggleConfig() return end DEW:Open(a, "children", function() local a = DEW.options.args.messages.args local b, save = DEW.options.args, nil a.msgcbt.type, a.msgmail.type, a.msgbank.type, a.msgah.type, a.msginst.type, a.msgbg.type = "text", "text", "text", "text", "text", "text" a.message_blockparty.type, a.message_blockduel.type, a.message_blocktrade.type = "text", "text", "text" a.message_blockguildinvite.type, a.message_blockguildpetition.type = "text", "text" b.aceConfig.order = 35 b.blizzConfig.order = 40 b.activated.order = 45 DEW:FeedAceOptionsTable(DEW.options) end) --fix the menu position to not obscurate bar icons AdjustDewdropPosition(a) end local function Anti_AddException() for i, j in pairs(_.y) do for k, l in ipairs(_.z) do if i == l[1] and j == l[2] then -- should not occur but safer if not _.db.profile.anti_hidenotification then _:Print(L["Has detected this user already temporarily allowed"].." "..L["to start"]..": "..i) end wipe(_.y) return end end table.insert(_.z, #_.z + 1, { i, j }) if not _.db.profile.anti_hidenotification then _:Print(L["Temporarily allows"].." \""..j.."\" "..L["to start"]..": "..i) end SendChatMessage(sig..L["Has allowed you to retry one time"]..": "..i, "WHISPER", nil, j) wipe(_.y) return end if not _.db.profile.anti_hidenotification then _:Print(L["Has not found a blocked action to temporarily allow"]) end wipe(_.y) end local function Anti_DelException() local size = #_.z if size > 0 then if not _.db.profile.anti_hidenotification then _:Print(L["Has removed the exception for the user"].." \"".._.z[#_.z][2].."\" "..L["to start"]..": ".._.z[#_.z][1]) end SendChatMessage(sig..L["Has disallowed you to retry one time"]..": ".._.z[#_.z][1], "WHISPER", nil, _.z[#_.z][2]) table.remove(_.z, #_.z) return end if not _.db.profile.anti_hidenotification then _:Print(L["Has not found an exception set"]) end end local function OnLDBClick(self, button) if button == "LeftButton" then if IsControlKeyDown() then if IsAltKeyDown() then _.db.profile.activated = not _.db.profile.activated _.ToggleActive() elseif IsShiftKeyDown() then Anti_AddException() else _.ToggleConfig() end elseif IsShiftKeyDown() then if IsControlKeyDown() then Anti_AddException() else _.AutoSwitch(nil, true) end else ToggleDewdrop(self) end elseif button == "RightButton" then if IsControlKeyDown() then if IsShiftKeyDown() then Anti_DelException() else ToggleDewdrop(self) end else ToggleDewdrop(self) end end end local function UpdateTooltip(g) local db = _.db.profile if _.db.profile.showtooltip then if _.db.profile.ubertooltip then local owner = GameTooltip:GetOwner() GameTooltip_SetDefaultAnchor(g, owner) end g:ClearLines() g:AddLine(" ") getglobal(g:GetName().."TextLeft1"):SetText("EasyDND") getglobal(g:GetName().."TextRight1"):SetText(L["AntiParasites"]) getglobal(g:GetName().."TextRight1"):SetTextColor(0.99999780301005, 0.81960606575012, 0) getglobal(g:GetName().."TextRight1"):Show() g:AddLine(" ") g:AddLine(" ") getglobal(g:GetName().."TextLeft3"):SetText(" "..CheckLDBFlag()) g:AddLine(" ") getglobal(g:GetName().."TextLeft4"):SetText(" "..CheckStatus(db.modeinst).." "..L["PvE"]) getglobal(g:GetName().."TextRight4"):SetText(L["IsFriend"].." "..CheckStatus(db.anti_allowfriends).." ") getglobal(g:GetName().."TextRight4"):SetTextColor(0.99999780301005, 0.81960606575012, 0) getglobal(g:GetName().."TextRight4"):Show() g:AddLine(" ") getglobal(g:GetName().."TextLeft5"):SetText(" "..CheckStatus(db.modebg).." "..L["PvP"]) getglobal(g:GetName().."TextRight5"):SetText(L["IsGuild"].." "..CheckStatus(db.anti_allowguild).." ") getglobal(g:GetName().."TextRight5"):SetTextColor(0.99999780301005, 0.81960606575012, 0) getglobal(g:GetName().."TextRight5"):Show() g:AddLine(" ") getglobal(g:GetName().."TextLeft6"):SetText(" "..CheckStatus(db.modeah).." "..L["AH"]) getglobal(g:GetName().."TextRight6"):SetText(L["Party"].." "..CheckStatus(db.anti_blockparty).." ") getglobal(g:GetName().."TextRight6"):SetTextColor(0.99999780301005, 0.81960606575012, 0) getglobal(g:GetName().."TextRight6"):Show() g:AddLine(" ") getglobal(g:GetName().."TextLeft7"):SetText(" "..CheckStatus(db.modemail).." "..L["Mail"]) getglobal(g:GetName().."TextRight7"):SetText(L["Duel"].." "..CheckStatus(db.anti_blockduel).." ") getglobal(g:GetName().."TextRight7"):SetTextColor(0.99999780301005, 0.81960606575012, 0) getglobal(g:GetName().."TextRight7"):Show() g:AddLine(" ") getglobal(g:GetName().."TextLeft8"):SetText(" "..CheckStatus(db.modebank).." "..L["Bank"]) getglobal(g:GetName().."TextRight8"):SetText(L["Trade"].." "..CheckStatus(db.anti_blocktrade).." ") getglobal(g:GetName().."TextRight8"):SetTextColor(0.99999780301005, 0.81960606575012, 0) getglobal(g:GetName().."TextRight8"):Show() g:AddLine(" ") getglobal(g:GetName().."TextLeft9"):SetText(" "..CheckStatus(db.modecbt).." "..L["Combat"]) getglobal(g:GetName().."TextRight9"):SetText(L["Guild"].." "..CheckStatus(db.anti_blockguildinvite).." ") getglobal(g:GetName().."TextRight9"):SetTextColor(0.99999780301005, 0.81960606575012, 0) getglobal(g:GetName().."TextRight9"):Show() g:AddLine(" ") getglobal(g:GetName().."TextLeft10"):SetText(" "..CheckStatus(db.modednd, true).." "..L["ModeDND"]) getglobal(g:GetName().."TextRight10"):SetText(L["Petition"].." "..CheckStatus(db.anti_blockguildpetition).." ") getglobal(g:GetName().."TextRight10"):SetTextColor(0.99999780301005, 0.81960606575012, 0) getglobal(g:GetName().."TextRight10"):Show() g:AddLine(" ") getglobal(g:GetName().."TextLeft11"):SetText(" "..CheckStatus(db.toggleNdnd).." "..L["NameDND"]) g:AddLine(" ") getglobal(g:GetName().."TextLeft12"):SetText(" "..CheckStatus(db.toggleNafk).." "..L["NameAFK"]) if _.db.profile.showhints then g:AddLine(" ") g:AddLine("|cffeda55f"..L["Click|r to open the Dewdrop quick\npanel."], 0.2, 1, 0.2) g:AddLine("|cffeda55f"..L["Ctrl-Click|r to open the AceGUI\nconfiguration window."], 0.2, 1, 0.2) g:AddLine("|cffeda55f"..L["Shift-Click|r to instantly switch your\nstatus to %s mode or remove the\ncurrent mode."]:format(_.CheckMode()), 0.2, 1, 0.2) g:AddLine("|cffeda55f"..L["Ctrl-Shift-LClick|r add an AntiParasites\nexception. The last blocked user and\nevent will be allowed only one time\nfor the same user and event only."], 0.2, 1, 0.2) g:AddLine("|cffeda55f"..L["Ctrl-Shift-RClick|r del an AntiParasites\nexception. It removes from the last\nexception added to the first if\nrepeated clicks."], 0.2, 1, 0.2) g:AddLine("|cffeda55f"..L["Ctrl-Alt-Click|r to enable/disable the\naddon."], 0.2, 1, 0.2, 0) -- GameTooltip wrap option is too buggy shame on Blizzard! end end end local function UpdateLDB() _.LDB.text = CheckLDBFlag() if _.db.profile.showtooltip and GameTooltip:IsVisible() then local owner = GameTooltip:GetOwner() or GameTooltip local name = owner:GetName() or "not" if owner and strfind(name, "EasyDND") then UpdateTooltip(GameTooltip) end end if _.db.profile.toggleNdnd or _.db.profile.toggleNafk then _.SetAutoToggleNames() end end local function SetLDBEvents() LDB_EV:RegisterEvent("PLAYER_FLAGS_CHANGED", UpdateLDB) LDB_EV:RegisterEvent("ZONE_CHANGED_NEW_AREA", UpdateLDB) end -- this function is used to clone the default table for DewdropLib to apply changes on it without breaking the Ace3 table. -- http://lua-users.org/wiki/CopyTable -- Changes to the table are committed in the ToggleDewdrop function local function deepcopy(object) local lookup_table = {} local function _copy(object) if type(object) ~= "table" then return object elseif lookup_table[object] then return lookup_table[object] end local new_table = {} lookup_table[object] = new_table for index, value in pairs(object) do new_table[_copy(index)] = _copy(value) end return setmetatable(new_table, getmetatable(object)) end return _copy(object) end local function InitLDB() local ldb = LDB:NewDataObject("EasyDND", { type = "data source", text = CheckLDBFlag(), icon = ICONON, OnClick = OnLDBClick, }) function ldb.OnTooltipShow(g) if _.db.profile.showtooltip then UpdateTooltip(g) end end _.LDB = ldb if ICO then _.LDB.ICO = ICO end _.LDB.ICONON = ICONON _.LDB.ICONOFF = ICONOFF _.LDB.ToggleMinimap = ToggleMinimap _.LDB.SetLDBEvents = SetLDBEvents _.LDB.UpdateLDB = UpdateLDB _.LDB.CheckLDBFlag = CheckLDBFlag end _.LDB = {} _.LDB.InitLDB = InitLDB if DEW then DEW.options = deepcopy(_.options) end