Thread Tools Display Modes
07-14-07, 10:51 AM   #1
grievious
A Defias Bandit
Join Date: Jul 2007
Posts: 3
An addon to hide a Chat Frame, when we are in raid ?

Hi,

I would like to make an addon who should be able to hide one chat frame when we are in raid party.

For exemple, I have 2 chat frame, one to the left where i have my "Guild", "party" an "raid" chan and the second chat frame, to the right, where we have the "General", "Cry" and "Said" chan. It's this second chan i'would like to hide when i'm in a raid group.

I've tried to make it alone, but it dosen't work.

This my files :

1st the .TOC file (HicheChat.toc)
Code:
## Interface: 20100
## Author: Shamonyou
## Title: HideChat
## Notes: Hide a chat frame in raid
## Version: 0.00.1
## DefaultState: Enabled
## SavedVariables: hidechat

HideChat.lua
2d the .lua file (HideChat.lua)

Code:
function AutohideChat_OnLoad()
this:RegisterEvent("RAID_ROSTER_UPDATE");
end

function AutohideChat_OnEvent(event)
if(event=="RAID_ROSTER_UPDATE") then
if ChatFrame3:IsShown() then ChatFrame3:Hide() else ChatFrame3:Show() end
end
end
When i make a simply macro, it works :

/script if ChatFrame1:IsShown() then ChatFrame1:Hide() else ChatFrame1:Show() end

Can you Help me please ?
  Reply With Quote
07-14-07, 11:00 AM   #2
Dreadlorde
A Pyroguard Emberseer
 
Dreadlorde's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 2,302
why don't you just put them together and switch between tabs?
__________________

Funtoo - Plan 9 - Windows 7
  Reply With Quote
07-14-07, 12:25 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Try...

Code:
function AutoHideChat_OnLoad(self)
     self:RegisterEvent("RAID_ROSTER_UPDATE")
end

function AutoHideChat:OnEvent()
    if ChatFrame3:IsShown() 
        then ChatFrame3:Hide() 
        else ChatFrame3:Show() 
    end
end
Not 100% sure that will work, but just want to make sure you're registering for events properly, and get rid of that extra "end". (You might need one before "else", don't recall.) I also don't think you need to check for the event, since you're registering for just one.

Then again, I usually leave this stuff up to the professionals.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-14-07, 12:50 PM   #4
Layrajha
A Frostmaul Preserver
 
Layrajha's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 275
EDITED: Better answer belowby Phanx (here: hooking many functions a complicated way instead of 1 an easy way, nice...)

Last edited by Layrajha : 07-14-07 at 10:12 PM.
  Reply With Quote
07-14-07, 02:12 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You don't need "## DefaultState: Enabled" in your TOC; it's assumed.

In your Lua, in the OnEvent handler, you don't need the "if event == something" if you're only registering one event. Also, you need to create a frame to actually call the OnLoad and OnEvent handlers. Finally, RAID_ROSTER_UPDATE is called every time someone joins or leaves your raid group, or groups are changed. If you just want to hide the chat frame while you're in a raid and show it when you're not, try this:

Code:
local frame = CreateFrame("Frame")
frame:SetSecript("OnEvent", function()
	if GetNumRaidMembers() > 0 and ChatFrame3:IsShown() then
		ChatFrame3:Hide()
	elseif not ChatFrame3:IsShown() then
		ChatFrame3:Show()
	end
end)
frame:RegisterEvent("RAID_ROSTER_UPDATE")
  Reply With Quote
07-14-07, 02:15 PM   #6
Layrajha
A Frostmaul Preserver
 
Layrajha's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 275
EDITED: Removed for the same reason as above.

Last edited by Layrajha : 07-14-07 at 10:12 PM.
  Reply With Quote
07-14-07, 04:28 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Hmm. Wouldn't it be easier to just hook the OnShow and hide it again if necessary?

Code:
local hiding
local frame = CreateFrame("Frame")
frame:SetScript("OnLoad", function()
	ChatFrame3:HookScript("OnShow", function() if hiding then this:Hide() end end)
end)
frame:SetSecript("OnEvent", function()
	if GetNumRaidMembers() > 0 then
		hiding = true
		ChatFrame3:Hide()
	else
		hiding = false
		ChatFrame3:Show()
	end
end)
frame:RegisterEvent("RAID_ROSTER_UPDATE")
  Reply With Quote
07-14-07, 04:52 PM   #8
grievious
A Defias Bandit
Join Date: Jul 2007
Posts: 3
Thanks all for your help !!!

@Phanx : your first script work perfectly but as we expect with the "RAID_ROSTER_UPDATE", the chat frame appear and desappear when the raid change.

How can we fix it ?

Last edited by grievious : 07-14-07 at 05:26 PM.
  Reply With Quote
07-14-07, 05:37 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Use the second one I posted. I removed the shown checks so it won't do the toggle, just hide the frame if you have raid members, show it if you don't.
  Reply With Quote
07-14-07, 07:26 PM   #10
grievious
A Defias Bandit
Join Date: Jul 2007
Posts: 3
Thanks a lot, your second script works, it's really nice.

I try now to make the same operation with an action bar in order to have the perfect raid Ui.
  Reply With Quote
07-14-07, 10:08 PM   #11
Layrajha
A Frostmaul Preserver
 
Layrajha's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 275
Originally Posted by Phanx
Hmm. Wouldn't it be easier to just hook the OnShow and hide it again if necessary?
Actually, it's easier.
When I coded my addon, I've done those hooks by reflex without thinking too much. Now that I see both solutions, and as mine is already coded for me and working, I won't change back, as performance-wise, I think they are both really low CPU and memory consuming (mine being a tiny little bit less CPU consuming and a tiny little bit more memory consuming, I guess, but those addons can be neglicted i'd say), but if I have to do it again, or something similar, I'll try to think about hacking OnShow methods instead
And HookScript that I didn't know makes it so easy o_O I would have used some "frame:Set ( function() blabla frame:Get() end)" ://

Last edited by Layrajha : 07-14-07 at 10:10 PM.
  Reply With Quote
05-01-08, 02:48 PM   #12
Everglow
An Aku'mai Servant
 
Everglow's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
Actually, your original solution:

Originally Posted by Phanx View Post
...try this:

Code:
local frame = CreateFrame("Frame")
frame:SetSecript("OnEvent", function()
    if GetNumRaidMembers() > 0 and ChatFrame3:IsShown() then
        ChatFrame3:Hide()
    elseif not ChatFrame3:IsShown() then
        ChatFrame3:Show()
    end
end)
frame:RegisterEvent("RAID_ROSTER_UPDATE")
Would work fine with a slight logic adjustment:

Code:
local frame = CreateFrame("Frame")
frame:SetSecript("OnEvent", function()
    if GetNumRaidMembers() > 0 then
       if ChatFrame3:IsShown() then
          ChatFrame3:Hide()
       end
   elseif not ChatFrame3:IsShown() then
        ChatFrame3:Show()
   end
end)
frame:RegisterEvent("RAID_ROSTER_UPDATE")
I'm not sure whether this or your second solution would be more efficient
__________________
Everglow - Sisters of Elune/US

Last edited by Everglow : 05-01-08 at 02:53 PM. Reason: clean up post
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » An addon to hide a Chat Frame, when we are in raid ?


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