Thread Tools Display Modes
02-26-10, 05:35 AM   #1
Pseudopod
A Deviate Faerie Dragon
Join Date: Apr 2008
Posts: 16
chat formatting (oChat)

Hello. I'm trying to modify the formatting of chat with oChat to my liking. Basically:

guild chat: 1245 Hunterx: blah
say: 1245 Mightydk: hallo!
trade: 1245 Bankalt: WTS lots of expensive stuff
Emote: 1245 You are hungry!

etc. Basically:
-The only indication for channels is the color
-No brackets around names
-That's about it?

So far I haven't successfully been able to do this without some not working as intended stuff.

I think this is the relevant part:
Code:
local ts = "|cffffffff|HoChat|h%s|h|r %s"
 
local origs = {}
  
CHAT_GUILD_GET = '|Hchannel:Guild|h%s:\32'
... other chats
 
-- 1: index, 2: channelname, 3: twatt
-- Examples are based on this: [1. Channel] Otravi: Hi
--local str = "[%2$.3s] %s" -- gives: [Cha] Otravi: Hi
--local str = "[%d. %2$.3s] %s" -- gives: [1. Cha] Otravi: Hi
local str = "%3$s" 
local channel = function(...)
	return str:format(...)
end
 
local AddMessage = function(self, text, ...)
	if(type(text) == "string") then
	text = text:gsub('|Hchannel:(%d+)|h%[?(.-)%]?|h.+(|Hplayer.+)', channel)
		text = ts:format(date"%H%M", text)
	end

	return _AddMessage(self, text, ...)
end
With this code "number channels" (Trade, General, custom channels) work fine. But guild chat etc don't have clickable names (can't click on a name to whisper etc) if they are like above:
CHAT_GUILD_GET = '|Hchannel:Guild|h%s:\32'
If I change that to
CHAT_GUILD_GET = '|Hchannel:Guild|h\32|h%s:\32' the names are clickable but there's an extra space between timestamp and name. Also in each case the names have brackets of course.

If I change
local ts = "|cffffffff|HoChat|h%s|h|r %s" to

Code:
local ts = "|cffffffff|HoChat|h%s|h|r%s" --AND 
local str = " %3$s" --AND 
CHAT_GUILD_GET = '|Hchannel:Guild|h |h%s:\32'
Every channel shows correctly but there's no space between the timestamp and name in emote/system/npc messages. Then there's always the issue of brackets around names, I don't really know how to remove them.

At one point I had
Code:
	if(type(text) == "string") then
		text = text:gsub("|Hplayer:([^:]+):(%d+)|h%[(.-)%]|h", "|Hplayer:%1:%2|h%3|h")
		text = text:gsub("%[(%d+)%. (.+)%].+(|Hplayer.+)", channel)
		text = ts:format(date"%H%M", text)
	end
that does remove the brackets but there's something wrong with that too since the names aren't clickable in trade etc. (guild works if I add the space in guild chat formatting section)

Is there someone who could help me with this?

Last edited by Pseudopod : 02-26-10 at 05:41 AM.
  Reply With Quote
02-26-10, 06:31 AM   #2
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Look at the code of ncChat.
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
02-26-10, 06:51 AM   #3
Beoko
Guest
Posts: n/a
This is much easier to accomplish than you think.

Change the CHAT_GUILD_GET to this:

Code:
CHAT_GUILD_GET = '|Hchannel:Guild|h|h%s:\32'
You were missing the end of an embedded hyperlink which caused the names to be unclickable, and when you tried to fix it yourself you accidentally added a second space escape sequence ("\32"). Changing the function AddMessage to this:

Code:
local AddMessage = function(self, text, ...)
    text = gsub(text, "%[%d+%. %w+%]", "")
    text = ts:format(date"%H%M", text)
    return _AddMessage(self, text, ...)
end
- should remove the brackets, while keeping the timestamp, but it's not entirely tested (it's a variation of what I use myself).
  Reply With Quote
02-26-10, 07:18 AM   #4
Pseudopod
A Deviate Faerie Dragon
Join Date: Apr 2008
Posts: 16
Originally Posted by Beoko View Post
Code:
CHAT_GUILD_GET = '|Hchannel:Guild|h|h%s:\32'
You were missing the end of an embedded hyperlink which caused the names to be unclickable, and when you tried to fix it yourself you accidentally added a second space escape sequence ("\32"). Changing the function AddMessage to this:
The reason there was a second space escape sequence was that if I didn't put anything between the |h|h, the game prints it as
"|Hchannel:GuildHunterx: hey guild!"
It seems to need something to replace the channel name with.

At nightcracker's suggestion I looked at ncChat's code (I've tried to view idChat for help previously btw) and added the second text = text:gsub, which works for removing the brackets. Thanks for that.
Code:
local AddMessage = function(self, text, ...)
	if(type(text) == "string") then
	text = text:gsub('|Hchannel:(%d+)|h%[?(.-)%]?|h.+(|Hplayer.+)', channel)
	text = text:gsub("(|Hplayer.-|h)%[(.-)%]|h", "%1%2|h")
		text = ts:format(date"%H%M", text)
	end

	return _AddMessage(self, text, ...)
end
So the question still remains, how do I replace a channel name with absolutely nothing? :P
  Reply With Quote
02-26-10, 07:38 AM   #5
Beoko
Guest
Posts: n/a
I'm sorry. I've never really bothered completely omitting channel numbers or names so I never bothered to test embedded hyperlinks directly next to each other. I just tested this in game, it will not show the trailing guild hyperlink and it will let you click the player to send them a tell:
Code:
CHAT_GUILD_GET = '|h%s:\32'
  Reply With Quote
02-26-10, 07:49 AM   #6
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Eehm, as I told you, look at the code of ncChat and your a lot closer to your goal. But I'm nice, so I did the work for you:

Code:
text = text:gsub("|Hchannel:[^|]+|h[^|]+|h ", "")
text = text:gsub("(|Hplayer.-|h)%[(.-)%]|h", "%1%2|h")
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
02-26-10, 07:55 AM   #7
Pseudopod
A Deviate Faerie Dragon
Join Date: Apr 2008
Posts: 16
Originally Posted by Beoko View Post
I'm sorry. I've never really bothered completely omitting channel numbers or names so I never bothered to test embedded hyperlinks directly next to each other. I just tested this in game, it will not show the trailing guild hyperlink and it will let you click the player to send them a tell:
Code:
CHAT_GUILD_GET = '|h%s:\32'
I'm sorry, I didn't mean to sound snappy or anything. Anyways, It seems every message is treated exactly right now. Thank you very much.

Originally Posted by nightcracker View Post
Eehm, as I told you, look at the code of ncChat and your a lot closer to your goal. But I'm nice, so I did the work for you:

Code:
text = text:gsub("|Hchannel:[^|]+|h[^|]+|h ", "")
text = text:gsub("(|Hplayer.-|h)%[(.-)%]|h", "%1%2|h")
And I did what you told and came up with my own conclusions. I just don't have the tiniest clue about all the replacement mark up stuff so I didn't know how to produce the first line. And just adding the 2nd line made it work anyways with the suggestions above. :P But sure that's a lot cleaner and no need for the other replacement stuff. Thanks to you too

edit: Something I noticed though. oChat's memory usage is now 99.96 KB. What's up?

Last edited by Pseudopod : 02-26-10 at 08:03 AM.
  Reply With Quote
02-26-10, 08:00 AM   #8
Beoko
Guest
Posts: n/a
Originally Posted by nightcracker View Post
Eehm, as I told you, look at the code of ncChat and your a lot closer to your goal. But I'm nice, so I did the work for you:

Code:
text = text:gsub("|Hchannel:[^|]+|h[^|]+|h ", "")
text = text:gsub("(|Hplayer.-|h)%[(.-)%]|h", "%1%2|h")
I think he figured it out on his own. His post just before mine correctly adds timestamps and removes the trailing hyperlink code.

Originally Posted by Pseudopod View Post
I'm sorry, I didn't mean to sound snappy or anything. Anyways, It seems every message is treated exactly right now. Thank you very much.
Oh, no worries. I didn't mean to come off sounding like you sounded snappy if I did, either. ^^
  Reply With Quote
02-26-10, 08:13 AM   #9
Beoko
Guest
Posts: n/a
Originally Posted by Pseudopod View Post
edit: Something I noticed though. oChat's memory usage is now 99.96 KB. What's up?
Could be any number of things, but if I were to guess... calling two gsubs per AddMessage can add up if you have an excessive amount of chat happening. Mind posting your entirely edited lua file now?
  Reply With Quote
02-26-10, 08:19 AM   #10
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Originally Posted by Beoko View Post
Could be any number of things, but if I were to guess... calling two gsubs per AddMessage can add up if you have an excessive amount of chat happening. Mind posting your entirely edited lua file now?
ncChat uses the same method and has 7kB mem usage. Must be some memory leak of some kind. Make sure to use /run collectgarbage("collect") before comparising mem usage though.
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
02-26-10, 08:21 AM   #11
Pseudopod
A Deviate Faerie Dragon
Join Date: Apr 2008
Posts: 16
Originally Posted by Beoko View Post
Could be any number of things, but if I were to guess... calling two gsubs per AddMessage can add up if you have an excessive amount of chat happening. Mind posting your entirely edited lua file now?
Code:
local type = type
local tonumber = tonumber
local string_split = string.split
 
local _AddMessage = ChatFrame1.AddMessage
local _SetItemRef = SetItemRef
 
local buttons = {"UpButton", "DownButton", "BottomButton"}
local dummy = function() end
local ts = "|cffffffff|HoChat|h%s|h|r %s"
 
local origs = {}
 
local blacklist = {
	[ChatFrame2] = true,
	[ChatFrame4] = true,
}
 
CHAT_SAY_GET = '|Hchannel:Say|h*|h%s:\32'
CHAT_GUILD_GET = '|h%s:\32'
CHAT_RAID_GET = "|Hchannel:raid|h*|h%s:\32"
CHAT_PARTY_GET = "|Hchannel:Party|h*|h%s:\32"
CHAT_PARTY_LEADER_GET = '|Hchannel:party|h*|h%s:\32'
CHAT_PARTY_GUIDE_GET =  CHAT_PARTY_LEADER_GET
CHAT_RAID_WARNING_GET = "! %s:\32"
CHAT_RAID_LEADER_GET = "|Hchannel:raid|h*|h%s:\32"
CHAT_OFFICER_GET = "|Hchannel:o|h*|h%s:\32"
CHAT_BATTLEGROUND_GET = "|Hchannel:Battleground|h*|h%s:\32"
CHAT_BATTLEGROUND_LEADER_GET = "|Hchannel:Battleground|h*|h%s:\32"
 
-- 1: index, 2: channelname, 3: twatt
-- Examples are based on this: [1. Channel] Otravi: Hi
--local str = "[%2$.3s] %s" -- gives: [Cha] Otravi: Hi
--local str = "[%d. %2$.3s] %s" -- gives: [1. Cha] Otravi: Hi
local str = "%3$s" -- gives: 1 Otravi: Hi
local channel = function(...)
	return str:format(...)
end
 
local AddMessage = function(self, text, ...)
	if(type(text) == "string") then
	--text = text:gsub('|Hchannel:(%d+)|h%[?(.-)%]?|h.+(|Hplayer.+)', channel)
	text = text:gsub("|Hchannel:[^|]+|h[^|]+|h ", "")
	text = text:gsub("(|Hplayer.-|h)%[(.-)%]|h", "%1%2|h")
		text = ts:format(date"%H%M", text)
	end

	return _AddMessage(self, text, ...)
end

local scroll = function(self, dir)
	if(dir > 0) then
		if(IsShiftKeyDown()) then
			self:ScrollToTop()
		else
			self:ScrollUp()
		end
	elseif(dir < 0) then
		if(IsShiftKeyDown()) then
			self:ScrollToBottom()
		else
			self:ScrollDown()
		end
	end
end
 
for i=1, NUM_CHAT_WINDOWS do
	local cf = _G["ChatFrame"..i]
	cf:EnableMouseWheel(true)
 
	cf:SetFading(false)
	cf:SetScript("OnMouseWheel", scroll)
 
	for k, button in pairs(buttons) do
		button = _G["ChatFrame"..i..button]
		button:Hide()
		button.Show = dummy
	end
 
	if(not blacklist[cf]) then
		origs[cf] = cf.AddMessage
		cf.AddMessage = AddMessage
	end
end
 
buttons = nil
 
ChatFrameMenuButton:Hide()
ChatFrameMenuButton.Show = dummy
 
local eb = ChatFrameEditBox
eb:ClearAllPoints()
eb:SetAltArrowKeyMode(false)
eb:SetPoint("CENTER", "UIParent", 0, 0)
eb:SetPoint("CENTER", "UIParent", 0, 0)
eb:SetWidth(350)
 
local a, b, c = select(6, eb:GetRegions())
a:Hide(); b:Hide(); c:Hide()
 
ChatTypeInfo['SAY'].sticky = 1
ChatTypeInfo['YELL'].sticky = 1
ChatTypeInfo['PARTY'].sticky = 1
ChatTypeInfo['GUILD'].sticky = 1
ChatTypeInfo['OFFICER'].sticky = 1
ChatTypeInfo['RAID'].sticky = 1
ChatTypeInfo['RAID_WARNING'].sticky = 1
ChatTypeInfo['BATTLEGROUND'].sticky = 1
ChatTypeInfo['WHISPER'].sticky = 1
ChatTypeInfo['CHANNEL'].sticky = 1
 
-- Modified version of MouseIsOver from UIParent.lua
local MouseIsOver = function(frame)
	local s = frame:GetParent():GetEffectiveScale()
	local x, y = GetCursorPosition()
	x = x / s
	y = y / s
 
	local left = frame:GetLeft()
	local right = frame:GetRight()
	local top = frame:GetTop()
	local bottom = frame:GetBottom()
 
	-- Hack to fix a symptom not the real issue
	if(not left) then
		return
	end
 
	if((x > left and x < right) and (y > bottom and y < top)) then
		return 1
	else
		return
	end
end
 
local borderManipulation = function(...)
	for l = 1, select("#", ...) do
		local obj = select(l, ...)
		if(obj:GetObjectType() == "FontString" and MouseIsOver(obj)) then
			return obj:GetText()
		end
	end
end

SetItemRef = function(link, text, button, ...)
	if(link:sub(1, 5) ~= "oChat") then return _SetItemRef(link, text, button, ...) end
 
	local text = borderManipulation(SELECTED_CHAT_FRAME:GetRegions())
	if(text) then
		text = text:gsub("|c%x%x%x%x%x%x%x%x(.-)|r", "%1")
		text = text:gsub("|H.-|h(.-)|h", "%1")
 
		eb:Insert(text)
		eb:Show()
		eb:HighlightText()
		eb:SetFocus()
	end
end
(It's not polished yet :P) When I removed the last "SetItemRef = function(link, text, button, ...)" part it dropped to 2kb actually.
  Reply With Quote
02-26-10, 08:23 AM   #12
Ferous
Sheer Sense of Doom
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 863
Off topic: Why are so many people worried about memory? You seriously concerned that oChat is using under 1 MB of memory?
  Reply With Quote
02-26-10, 08:28 AM   #13
Pseudopod
A Deviate Faerie Dragon
Join Date: Apr 2008
Posts: 16
Originally Posted by Ferous View Post
Off topic: Why are so many people worried about memory? You seriously concerned that oChat is using under 1 MB of memory?
Not exactly. The fact that it has previously used far less and that other similar addons use the amounts reported here compared to 100x usage indicates to me that there might be something wrong and that the addon is not as optimal as it could be.

I.g. If there are 3 minimap addons that all can be made to look the same, I will choose the one with no config and minimal code over one that has a in-game config and lots of other stuff I don't need at all. In static things like minimap and chat where it's all about how you want something to look, I prefer the minimalistic version. When it comes to boss mods, I will choose the one that has the best warnings and timers over one that uses less memory but doesn't have everything I need.

In addition, since I'm not a lua expert at all and I'm still tweaking the code to my liking, something like that also is the only way of knowing if my editings are baaaad.

(I've edited this like 100 times now lol). Immediately after garbage collection the mem usage is now (with a "polished" version) 1.44 kb. It goes steadily up, but that's just normal cause it does need to edit every line?

Last edited by Pseudopod : 02-26-10 at 08:38 AM.
  Reply With Quote
02-26-10, 08:32 AM   #14
Beoko
Guest
Posts: n/a
Originally Posted by Pseudopod View Post
Code:
local type = type
local tonumber = tonumber
local string_split = string.split
 
local _AddMessage = ChatFrame1.AddMessage
local _SetItemRef = SetItemRef
 
local buttons = {"UpButton", "DownButton", "BottomButton"}
local dummy = function() end
local ts = "|cffffffff|HoChat|h%s|h|r %s"
 
local origs = {}
 
local blacklist = {
    [ChatFrame2] = true,
    [ChatFrame4] = true,
}
 
CHAT_SAY_GET = '|Hchannel:Say|h*|h%s:\32'
CHAT_GUILD_GET = '|h%s:\32'
CHAT_RAID_GET = "|Hchannel:raid|h*|h%s:\32"
CHAT_PARTY_GET = "|Hchannel:Party|h*|h%s:\32"
CHAT_PARTY_LEADER_GET = '|Hchannel:party|h*|h%s:\32'
CHAT_PARTY_GUIDE_GET =  CHAT_PARTY_LEADER_GET
CHAT_RAID_WARNING_GET = "! %s:\32"
CHAT_RAID_LEADER_GET = "|Hchannel:raid|h*|h%s:\32"
CHAT_OFFICER_GET = "|Hchannel:o|h*|h%s:\32"
CHAT_BATTLEGROUND_GET = "|Hchannel:Battleground|h*|h%s:\32"
CHAT_BATTLEGROUND_LEADER_GET = "|Hchannel:Battleground|h*|h%s:\32"
 
-- 1: index, 2: channelname, 3: twatt
-- Examples are based on this: [1. Channel] Otravi: Hi
--local str = "[%2$.3s] %s" -- gives: [Cha] Otravi: Hi
--local str = "[%d. %2$.3s] %s" -- gives: [1. Cha] Otravi: Hi
local str = "%3$s" -- gives: 1 Otravi: Hi
local channel = function(...)
    return str:format(...)
end
 
local AddMessage = function(self, text, ...)
    if(type(text) == "string") then
    --text = text:gsub('|Hchannel:(%d+)|h%[?(.-)%]?|h.+(|Hplayer.+)', channel)
    text = text:gsub("|Hchannel:[^|]+|h[^|]+|h ", "")
    text = text:gsub("(|Hplayer.-|h)%[(.-)%]|h", "%1%2|h")
        text = ts:format(date"%H%M", text)
    end

    return _AddMessage(self, text, ...)
end

local scroll = function(self, dir)
    if(dir > 0) then
        if(IsShiftKeyDown()) then
            self:ScrollToTop()
        else
            self:ScrollUp()
        end
    elseif(dir < 0) then
        if(IsShiftKeyDown()) then
            self:ScrollToBottom()
        else
            self:ScrollDown()
        end
    end
end
 
for i=1, NUM_CHAT_WINDOWS do
    local cf = _G["ChatFrame"..i]
    cf:EnableMouseWheel(true)
 
    cf:SetFading(false)
    cf:SetScript("OnMouseWheel", scroll)
 
    for k, button in pairs(buttons) do
        button = _G["ChatFrame"..i..button]
        button:Hide()
        button.Show = dummy
    end
 
    if(not blacklist[cf]) then
        origs[cf] = cf.AddMessage
        cf.AddMessage = AddMessage
    end
end
 
buttons = nil
 
ChatFrameMenuButton:Hide()
ChatFrameMenuButton.Show = dummy
 
local eb = ChatFrameEditBox
eb:ClearAllPoints()
eb:SetAltArrowKeyMode(false)
eb:SetPoint("CENTER", "UIParent", 0, 0)
eb:SetPoint("CENTER", "UIParent", 0, 0)
eb:SetWidth(350)
 
local a, b, c = select(6, eb:GetRegions())
a:Hide(); b:Hide(); c:Hide()
 
ChatTypeInfo['SAY'].sticky = 1
ChatTypeInfo['YELL'].sticky = 1
ChatTypeInfo['PARTY'].sticky = 1
ChatTypeInfo['GUILD'].sticky = 1
ChatTypeInfo['OFFICER'].sticky = 1
ChatTypeInfo['RAID'].sticky = 1
ChatTypeInfo['RAID_WARNING'].sticky = 1
ChatTypeInfo['BATTLEGROUND'].sticky = 1
ChatTypeInfo['WHISPER'].sticky = 1
ChatTypeInfo['CHANNEL'].sticky = 1
 
-- Modified version of MouseIsOver from UIParent.lua
local MouseIsOver = function(frame)
    local s = frame:GetParent():GetEffectiveScale()
    local x, y = GetCursorPosition()
    x = x / s
    y = y / s
 
    local left = frame:GetLeft()
    local right = frame:GetRight()
    local top = frame:GetTop()
    local bottom = frame:GetBottom()
 
    -- Hack to fix a symptom not the real issue
    if(not left) then
        return
    end
 
    if((x > left and x < right) and (y > bottom and y < top)) then
        return 1
    else
        return
    end
end
 
local borderManipulation = function(...)
    for l = 1, select("#", ...) do
        local obj = select(l, ...)
        if(obj:GetObjectType() == "FontString" and MouseIsOver(obj)) then
            return obj:GetText()
        end
    end
end

SetItemRef = function(link, text, button, ...)
    if(link:sub(1, 5) ~= "oChat") then return _SetItemRef(link, text, button, ...) end
 
    local text = borderManipulation(SELECTED_CHAT_FRAME:GetRegions())
    if(text) then
        text = text:gsub("|c%x%x%x%x%x%x%x%x(.-)|r", "%1")
        text = text:gsub("|H.-|h(.-)|h", "%1")
 
        eb:Insert(text)
        eb:Show()
        eb:HighlightText()
        eb:SetFocus()
    end
end
(It's not polished yet :P) When I removed the last "SetItemRef = function(link, text, button, ...)" part it dropped to 2kb actually.
Probably a combination of quite a few things happening frequently/simultaneously and uncollected garbage.

Originally Posted by Ferous View Post
Off topic: Why are so many people worried about memory? You seriously concerned that oChat is using under 1 MB of memory?
Static memory is very harmless, but memory leaks can cause quite a few issues. I'm sure we wouldn't have reacted the same if oChat was supposed to be about 100 kB normally.
  Reply With Quote
02-26-10, 09:03 AM   #15
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Originally Posted by Ferous View Post
Off topic: Why are so many people worried about memory? You seriously concerned that oChat is using under 1 MB of memory?
Because normally the addon uses 2kB but all of a sudden it uses 50 times as much. That makes you wonder
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
02-26-10, 04:37 PM   #16
Ferous
Sheer Sense of Doom
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 863
It was a general question though :P But yeah, I guess people just aren't sure why they like low memory addons and interfaces :P Right now, my interface uses roughly 46MB lol, but I have no issues.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » chat formatting (oChat)


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off