Erik L. Vonderscheer [06-04-09 - 06:36]
diff --git a/TradeFilter3.lua b/TradeFilter3.lua
index be394ef..be0d58d 100644
--- a/TradeFilter3.lua
+++ b/TradeFilter3.lua
@@ -33,8 +33,8 @@ Basic structure and code from crashmstr (wowzn@crashmstr.com)
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
--]]
+
TradeFilter3 = LibStub("AceAddon-3.0"):NewAddon("TradeFilter3", "AceHook-3.0", "AceEvent-3.0", "AceConsole-3.0")
local TF3 = TradeFilter3
@@ -72,6 +72,7 @@ function TF3:OnInitialize()
{"[lL][fF] [tT][aA][nN][kK]",true},
{"[lL][fF] [hH][eE][aA][lL][eE][rR]",true},
{"[lL][fF]%d[mM]?",true},
+ {"[lL][fF][mM]?",true},
{"[lL][fF][gG]",true},
{"AH",true},
{"looking for work",true},
@@ -83,18 +84,18 @@ function TF3:OnInitialize()
},
}
}
-
+
self.db = LibStub("AceDB-3.0"):New("TradeFilter3DB", defaults, "Default");
-
+
local ACP = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db);
-
+
self:RegisterChatCommand("filter", function() self:OpenOptions() end)
self:RegisterChatCommand("tradefilter", function() self:OpenOptions() end)
-
+
local ACR = LibStub("AceConfigRegistry-3.0")
ACR:RegisterOptionsTable("TradeFilter3", options)
ACR:RegisterOptionsTable("TradeFilter3P", ACP)
-
+
-- Set up options panels.
self.OptionsPanel = ACD:AddToBlizOptions(self.name, L["TFR"], nil, "general")
self.OptionsPanel.channel = ACD:AddToBlizOptions(self.name, L["channelGroup"], self.name, "channelGroup")
@@ -192,22 +193,21 @@ function TF3:IsTurnOn()
return self.db.profile.turnOn
end
-function TF3:ToggleTurnOn(info, value)
- self.db.profile.turnOn = not self.db.profile.turnOn
- self.db.profile.turnOn = value
- if (value == "false") then
- value = "Disabled"
- elseif (value == "true") then
- value = "Enabled"
+function TF3:ToggleTurnOn()
+ if (self.db.profile.turnOn == false) then
+ print("|cFF33FF99TradeFilter3|r: " .. TF3.version .. " |cff00ff00Enabled|r")
+ self.db.profile.turnOn = not self.db.profile.turnOn
+ else
+ print("|cFF33FF99TradeFilter3|r: " .. TF3.version .. " |cffff8080Disabled|r")
+ self.db.profile.turnOn = not self.db.profile.turnOn
end
--- print("|cFF33FF99TradeFilter3|r: " .. TradeFilter3.version .. " |cff00ff00Enabled " .. tostring(value) .. "|r")
end
options = {
- type='group',
+ type='group',
name = TF3.name,
handler = TF3,
- args = {
+ args = {
general = {
type = "group",
name = TF3.name,
@@ -224,7 +224,7 @@ options = {
redirect = {
type = 'toggle',
order = 2,
- width = "double",
+ width = "full",
name = L["Redir"],
desc = L["RedirDesc"],
get = "IsRedirect",
@@ -248,9 +248,12 @@ options = {
func = function()
_G.ReloadUI()
end,
- --disabled = function()
- -- return not self:IsDebug or return not self:IsRedirect
- --end,
+ disabled = function()
+ if not TF3:IsRedirect() or not TF3:IsDebug() then
+ return false
+ end
+ return true
+ end,
order = -1,
},
},
@@ -261,7 +264,7 @@ options = {
width = "double",
disabled = false,
name = "Channel Selection",
- desc = "Channel Selection [Not Implemented Yet]",
+ desc = "Channel Selection",
args = {
tradeChannel = {
type = 'toggle',
@@ -365,89 +368,49 @@ options = {
}
--[[ Locals ]]--
+ local _G = _G
--local filtered = false
- local redirectFrame = nil
- local debugFrame = nil
+ local redirectFrame = "SPAM"
+ local debugFrame = "DEBUG"
local lastArg1
+ local lastArg2
---[[ Window Functions ]]--
-function TF3:FindOrCreateChatWindow(window, create)
- local frame = nil
---[[
- if frame == nil and create then
- frame = CreateFrame("Frame", window, UIParent)
- _G["ChatFrame" .. NUM_CHAT_WINDOWS+1] = frame
- --setglobal("ChatFrame" .. NUM_CHAT_WINDOWS+1, frame)
- frame:Show()
- if (TF3:IsDebug()) then TF3:SendMessageToChat(debugFrame,"TF3: created the frame " .. window) end
- if frame then
- DEFAULT_CHAT_FRAME:AddMessage("TF3: created the frame " .. window .. "", 1.0, 0.0, 0.0, 0.0, 53, 5.0)
- frame:AddMessage("TF3: created the frame " .. window)
- end
-
- for i=1,NUM_CHAT_WINDOWS do
- name, fontSize, r, g, b, alpha, shown, locked, docked = GetChatWindowInfo(i)
- if (TF3:IsDebug()) then TF3:SendMessageToChat(debugFrame, name .. " found") end
- if (name == window) then
- SetChatWindowShown(i, true)
- SetChatWindowDocked(i, true)
- SetChatWindowAlpha(i, 50)
- end
- end
- end
-]]--
-
+--[[ Window and Chat Functions ]]--
+function TF3:FindFrame(toFrame, msg)
for i=1,NUM_CHAT_WINDOWS do
- name, fontSize, r, g, b, alpha, shown, locked, docked = GetChatWindowInfo(i)
- if (TF3:IsDebug()) then
- TF3:SendMessageToChat(debugFrame, name .. " found")
- end
- if (name == window) then
- SetChatWindowShown(i, true)
- --SetChatWindowDocked(i+1, true)
- --SetChatWindowAlpha(i, 50)
- frame = getglobal("ChatFrame" .. i)
- frame:AddMessage("TradeFilter3: found the frame " .. window);
+ local name,_,_,_,_,_,_,_,_ = GetChatWindowInfo(i)
+ if (toFrame == name) then
+ toFrame = _G["ChatFrame" .. i]
+ toFrame:AddMessage(msg)
+ else
+ --TF3:CreateFrame(toFrame)
end
end
-
- return frame
end
---[[ Chat Functions ]]--
-function TF3:SendMessageToChat(frame, message)
- if frame then
- frame:AddMessage(message)
- end
+function TF3:CreateFrame(newFrame)
+ --Need to find the proper way to create a new chatframe that is docked to the default frame
end
--[[ PreFilter ]]--
local function PreFilter_OnEvent(...)
- --[[ Taken from SpamMeNot
- arg1: chat message
- arg2: author
- arg7: zone ID used for generic system channels (1 for General,
- 2 for Trade, 22 for LocalDefense, 23 for WorldDefense and
- 26 for LFG) not used for custom channels or if you joined
- an Out-Of-Zone channel ex: "General - Stormwind City"
- arg8: channel number
- ]]
- -- the arguments a1..a9 are all nil until Blizzard actually passes them
- -- we're expected to use global variables which is generally a bad idea
- -- global variables may not be available in a later patch so we have to do this:
+--[[----------------------------------------------------------------------------------
+Taken from SpamMeNot
+ arg1: chat message
+ arg2: author
+ arg7: zone ID used for generic system channels (1 for General,
+ 2 for Trade, 22 for LocalDefense, 23 for WorldDefense and
+ 26 for LFG) not used for custom channels or if you joined
+ an Out-Of-Zone channel ex: "General - Stormwind City"
+ arg8: channel number
+ the arguments a1..a9 are all nil until Blizzard actually passes them
+ we're expected to use global variables which is generally a bad idea
+ global variables may not be available in a later patch so we have to do this:
+------------------------------------------------------------------------------------]]
local filtered = false
local userID = arg2 or select(2, ...)
local zoneID = arg7 or select(7, ...)
local chanID = arg8 or select(8, ...)
- --TF3:SendMessageToChat(debugFrame,"userID, zoneID, chanID")
- if (TF3:IsDebug() and debugFrame == nil) then
- debugFrame = TF3:FindOrCreateChatWindow("DEBUG", true)
- TF3:SendMessageToChat(debugFrame,"*** Debug is ON: Passing PreFilter ***")
- end
- if (TF3:IsRedirect() and redirectFrame == nil) then
- redirectFrame = TF3:FindOrCreateChatWindow("SPAM", true)
- TF3:SendMessageToChat(redirectFrame,"*** Redirect is ON: Passing PreFilter ***")
- end
--[[ Check for Trade Channel and User setting ]]--
if (zoneID == 2 and TF3:IsFilterTrade() and userID ~= UnitName("Player")) then
filtered = TF3:TF3_OnEvent()
@@ -471,7 +434,7 @@ local function PreFilter_OnEvent(...)
filtered = TF3:TF3_OnEvent()
elseif (chanID == 0 and not TF3:IsFilterSAY()) then
filtered = false
- end
+ end
return filtered
end
@@ -479,39 +442,31 @@ end
function TF3:TF3_OnEvent(...)
local filtered = false
local filterFuncList = ChatFrame_GetMessageEventFilters("CHAT_MSG_CHANNEL")
- if (TF3:IsDebug() and debugFrame == nil) then
- debugFrame = TF3:FindOrCreateChatWindow("DEBUG", true)
- TF3:SendMessageToChat(debugFrame,"*** Debug is ON ***")
- end
- if (TF3:IsRedirect() and redirectFrame == nil) then
- redirectFrame = TF3:FindOrCreateChatWindow("SPAM", true)
- TF3:SendMessageToChat(redirectFrame,"*** Redirect is ON ***")
- end
if (filterFuncList and TF3:IsTurnOn()) then
filtered = true
if (TF3:IsDebug()) then
- TF3:SendMessageToChat(debugFrame, "arg1: " .. arg1 .. " arg2: " .. arg2)
+ TF3:FindFrame(debugFrame, "arg1: " .. arg1 .. " arg2: " .. arg2)
end
for i, matchIt in ipairs(TF3.db.profile.filter) do
if (TF3:IsDebug() and not TF3:GetAddFilter()) then
- TF3:SendMessageToChat(debugFrame, "Checking for Match with " .. matchIt[1])
+ TF3:FindFrame(debugFrame, "Checking for Match with " .. matchIt[1])
elseif (TF3:IsDebug() and TF3:GetAddFilter()) then
- TF3:SendMessageToChat(debugFrame, "Checking for Match with " .. matchIt[1])
- TF3:SendMessageToChat(debugFrame, TF3.db.profile.addfilter1)
- TF3:SendMessageToChat(debugFrame, TF3.db.profile.addfilter2)
- TF3:SendMessageToChat(debugFrame, TF3.db.profile.addfilter3)
+ TF3:FindFrame(debugFrame, "Checking for Match with " .. matchIt[1])
+ TF3:FindFrame(debugFrame, TF3.db.profile.addfilter1)
+ TF3:FindFrame(debugFrame, TF3.db.profile.addfilter2)
+ TF3:FindFrame(debugFrame, TF3.db.profile.addfilter3)
end
if(not TF3:GetAddFilter()) then
if matchIt[2] and string.find(arg1, matchIt[1]) then
if (TF3:IsDebug()) then
- TF3:SendMessageToChat(debugFrame, "|cff00ff00**** Matched ***|r")
+ TF3:FindFrame(debugFrame, "|cff00ff00**** Matched ***|r")
end
filtered = false
end
elseif(TF3:GetAddFilter()) then
if matchIt[2] and string.find(arg1, matchIt[1]) or string.find(arg1, TF3.db.profile.addfilter1) or string.find(arg1, TF3.db.profile.addfilter2) or string.find(arg1, TF3.db.profile.addfilter3) then
if (TF3:IsDebug()) then
- TF3:SendMessageToChat(debugFrame, "|cff00ff00**** Matched ***|r")
+ TF3:FindFrame(debugFrame, "|cff00ff00**** Matched ***|r")
end
filtered = false
end
@@ -520,10 +475,10 @@ function TF3:TF3_OnEvent(...)
if filtered == true then
if lastArg1 ~= arg1 or lastArg2 ~= arg2 then
if (TF3:IsDebug()) then
- TF3:SendMessageToChat(debugFrame, "|cff00ff00*** NO Match - Redirected ***|r")
+ TF3:FindFrame(debugFrame, "|cff00ff00*** NO Match - Redirected ***|r")
end
if (TF3:IsRedirect()) then
- TF3:SendMessageToChat(redirectFrame, "zID" .. string.format(CHAT_CHANNEL_GET, arg7) .. " cID" .. string.format(CHAT_CHANNEL_GET, arg8) .. " " .. string.format(CHAT_CHANNEL_GET, arg2) .. arg1)
+ TF3:FindFrame(redirectFrame, "zID:" .. string.format(CHAT_CHANNEL_GET, arg7) .. " cID:" .. string.format(CHAT_CHANNEL_GET, arg8) .. " - " .. string.format(CHAT_CHANNEL_GET, arg2) .. arg1)
end
lastArg1, lastArg2 = arg1, arg2
end