Thread Tools Display Modes
11-08-10, 02:01 PM   #1
v6o
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 399
How to find out how many chat windows/tabs

Are there any functions to find out how many chat windows or tabs are opened or do you just have to go with something like ChatFrame#:IsShown() ?
__________________
I stopped playing back World of Warcraft in 2010 and I have no plans on returning.
This is a dead account and if you want to continue any of my addons or make a fork then feel free to do so.
This is your permission slip.

If you need to contact me, do so on Twitter @v6ooo

Best regards, v6.
  Reply With Quote
11-09-10, 02:14 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Read through the code of rChat:
http://code.google.com/p/rothui/sour...e/trunk/rChat/

NUM_CHAT_WINDOWS has the max number of chatframes. Available at loadup.

There is another function that can return the actual number of active chatframes but that is available after loadup only.

Blizzard ChatFrame code is in FrameXML/FloatingChatFrame.lua / .xml

Check for "FCF_GetNumActiveChatFrames()" in https://github.com/tekkub/wow-ui-sou...gChatFrame.lua
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 11-09-10 at 02:16 AM.
  Reply With Quote
11-09-10, 02:50 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
This is a function I grabbed from the blizz chatframes file and tweaked it for my purposes somewhat. You can ignore the infoPanel sections as that is something I use so that my chat frame addons can talk to each other by validating that flag to know whether it can use that chat frame or not for their own uses.

Code:
--[[ Generate a list of active frames for locating an available frame to use ]]--
local function nUI_InfoPanel_Chat_ActiveFrames()
	local shownList = {};
	local dockedList = {};
	local infoPanelList = {};
	local count = 0;
	local chatFrame;
	
	-- Cycle through ChatFrames 1 to 10 ( the current NUM_CHAT_WINDOWS setting )
	for i=1, NUM_CHAT_WINDOWS do

		-- Get the chatFrame object for this possible frame
		chatFrame = _G["ChatFrame"..i];
	
		-- Is it supposed to be shown ?
		local _, _, _, _, _, _, shown = FCF_GetChatWindowInfo(i);
				
		-- ChatFrame should be valid but double check
		if ( chatFrame ) then
		
			-- If it is flagged as a shown window then add it to the shown list
			if ( shown ) then shownList[chatFrame:GetID()] = true; end
			
			-- If it is flagged as a docked window then add it to the docked list
			if ( chatFrame.isDocked ) then dockedList[chatFrame:GetID()] = true; end

			-- If an info panel is using it then we don't want to use it
			if ( chatFrame.infoPanel ) then infoPanelList[chatFrame:GetID()] = true; end
			
		end
	end
	
	-- return the lists for viewing later
	return shownList,dockedList,infoPanelList;
end
And this is the section of code I use it in ..
Code:
	-- If blizz is updating the chat windows then we want in so we can do our stuff
	elseif ( event == "UPDATE_CHAT_WINDOWS" ) then

		-- Get the current list of frames
		local shownList,dockedList,infoPanelList = nUI_InfoPanel_Chat_ActiveFrames();
		
		-- Use the one stored in the saved variables table
		gcframe = _G[ipc_chatFrame];
		
		local inUse = 0;
				
		-- Go through the list of available chat frames
		for i = 1, NUM_CHAT_WINDOWS do
		
			-- If we have already stored the frame to use then use it and don't bother looking anymore.
			if ( gcframe ) then 
				gcframe.infoPanel = true; 
				nUI_InfoPanel_Chat_Restore();
				break; 
			end
		
			-- Generate a chat frame object
			local cf = _G["ChatFrame"..i];
			
			-- If it is not in the shown or docked list then it *should* be available for use
			if ( not shownList[cf:GetID()] and not dockedList[cf:GetID()] and not infoPanelList[cf:GetID()] ) then
			
				-- Set our special variable with the frame we're gonna use
				gcframe = _G["ChatFrame"..i];

				-- Tell us that we are using it in an infoPanel as that isn't docked or shown
				gcframe.infoPanel = true;
				
				-- Initialise the rest of its settings
				nUI_InfoPanel_Chat_Initialise();
								
				-- We made our frame so we can stop looking for a spot
				break;
These two are pretty much the meat of my chat frame addons so hopefully they will help give you some ideas alongside those of zorks suggestions.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to find out how many chat windows/tabs


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