diff CyborgMMO7.lua @ 15:80192bc4a108

Replaced the global msg function with CyborgMMO_DPrint: - avoids conflicts with other addons ('msg' is too generic) - has 'print' semantics (several values accepted, calls tostring) - use AddMessage with a colored prefix, instead of plain SendChatMessage
author madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09
date Thu, 25 Apr 2013 01:29:55 +0000
parents 6cb9a2936580
children a6f4c8f86130
line wrap: on
line diff
--- a/CyborgMMO7.lua	Thu Apr 25 01:29:50 2013 +0000
+++ b/CyborgMMO7.lua	Thu Apr 25 01:29:55 2013 +0000
@@ -19,7 +19,7 @@
 --~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 function CyborgMMO_LoadStrings(self)
---~ 	msg("LoadStrings("..self:GetName()..") = "..CyborgMMO_StringTable[self:GetName()])
+--	CyborgMMO_DPrint("LoadStrings("..self:GetName()..") = "..CyborgMMO_StringTable[self:GetName()])
 	self:SetText(CyborgMMO_StringTable[self:GetName()])
 end
 
@@ -111,10 +111,10 @@
 	elseif event == "PLAYER_ENTERING_WORLD" then
 		CyborgMMO_EnteredWorld = true
 	elseif event == "PLAYER_ENTER_COMBAT" then
-		msg("PLAYER_ENTER_COMBAT")
+		CyborgMMO_DPrint("PLAYER_ENTER_COMBAT")
 		CyborgMMO_Close()
 	else
-		msg("Event is "..tostring(event))
+		CyborgMMO_DPrint("Event is "..tostring(event))
 	end
 
 	-- Fire Loading if and only if the player is in the world and vars are loaded
@@ -185,7 +185,7 @@
 	local buttonFrame,parentFrame,name = CyborgMMO_CallbackFactory.Instance().AddCallback(fn)
 	local result = SetOverrideBindingClick(parentFrame, true, CyborgMMO_Mode[modeNum], name, "LeftButton")
 	if result ~= 1 then
-		msg("Failed to Bind modeChange")
+		CyborgMMO_DPrint("Failed to bind mode change")
 	end
 end
 
@@ -226,9 +226,26 @@
 	end
 end
 
-function msg(m)
-	local id,name = GetChannelName("Debug")
-	SendChatMessage(m, "CHANNEL", nil, id)
+function CyborgMMO_GetDebugFrame()
+	for i=1,NUM_CHAT_WINDOWS do
+		local windowName = GetChatWindowInfo(i);
+		if windowName == "Debug" then
+			return getglobal("ChatFrame" .. i)
+		end
+	end
+end
+
+local log_prefix = "|cffff6666".."CyborgMMO".."|r:"
+
+function CyborgMMO_DPrint(...)
+	local debugframe = CyborgMMO_GetDebugFrame()
+	if debugframe then
+		local t = {log_prefix, ...}
+		for i=1,select('#', ...)+1 do
+			t[i] = tostring(t[i])
+		end
+		debugframe:AddMessage(table.concat(t, ' '))
+	end
 end
 
 function CyborgMMO_SetMainPageSize(percent)