WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Problem Script kgpanels & recount (https://www.wowinterface.com/forums/showthread.php?t=42559)

lemmi13 02-07-12 05:12 AM

SOLVED: Problem Script kgpanels & recount
 
Hi

I'd like to hide recount when I'm not in a party oder raid. Therefore I wrote some Scripts in kgpanels.

OnLoad:
Code:

self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PARTY_MEMBERS_CHANGED")
self:RegisterEvent("RAID_ROSTER_UPDATE")

OnEvent:
Code:

local party_members = GetNumPartyMembers();
local raid_members = GetNumRaidMembers();
if (party_members < 1 and raid_members < 1) then
  Recount.MainWindow:Hide();
  self:Hide();
else
  Recount.RefreshMainWindow();
  Recount.MainWindow:Show();
  self:Show();
end;

The Box in kgpanels hides, when I'm not in a group but recount is still visible.


The funny things is that when I create an oncklick event within kgpanels:

Code:

Recount.MainWindow:Hide();
self:Hide();

or run a macro with

Code:

/run Recount.MainWindow:Hide();
Recount Hides.


Where is the problem in my kgpanel scripts? I can't figure out the misstake.


Thanks in advance for any help

Cheers

lemmi

Aanson 02-07-12 01:48 PM

Your script is good, it's Recount that's causing your problem. It seems to have a mind of it's own when it comes to showing and hiding.

You can parent the Recount panel to your kgPanels panel though and use the following code:


OnLoad
Lua Code:
  1. self:RegisterEvent("PARTY_MEMBERS_CHANGED")
  2. self:RegisterEvent("RAID_ROSTER_UPDATE")
  3. Recount_MainWindow:SetParent(self)

OnEvent
Lua Code:
  1. local pmems = GetNumPartyMembers()
  2. local rmems = GetNumRaidMembers()
  3. if (pmems < 1 and rmems < 1) then -- you're neither in a party or a raid
  4.   self:Hide()
  5. elseif (pmems >= 1 or rmems >= 1) then -- it knows it needs to do something
  6.   self:Show() -- you're panel (and Recount) shows
  7. end

That should work. Because you've told Recount to parent to your own panel at OnLoad, it can only show when your panel does, so you should be in a position where you just need to tell your panel what to do.

While I'm at it, you can add this to OnLoad too to ensure that your panel always re-sizes correctly whenever Recount_MainWindow's size changes.

Ordinarily, anchoring your frame to 2 opposing corners of another frame at OnLoad should ensure that your frame and the other frame remain the same size regardless, but that doesn't seem to be the case with kgPanels. Hence, the following is required (untested):

OnLoad
Lua Code:
  1. Recount_MainWindow:HookScript("OnSizeChanged", function
  2.   self:ClearAllPoints()
  3.   self:SetPoint("TOPLEFT", Recount_MainWindow, "TOPLEFT", -2, 2)
  4.   self:SetPoint("BOTTOMRIGHT", Recount_MainWindow, "BOTTOMRIGHT", 2, -2)
  5. end)

Put Recount in the "Script Dependences" bit to prevent problems during OnLoad.

Hope this helped.

lemmi13 02-07-12 04:15 PM

Ahh :D Great! Thanks for your help.

I just added

Code:

Recount.MainWindow:SetParent(self)
to OnLoad and everything is fine.


So for the Frame the working script is:


OnLoad:
Code:

self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PARTY_MEMBERS_CHANGED")
self:RegisterEvent("RAID_ROSTER_UPDATE")

Recount.MainWindow:SetParent(self)

OnEvent:
Code:

local party_members = GetNumPartyMembers();
local raid_members = GetNumRaidMembers();
if (party_members < 1 and raid_members < 1) then
  self:Hide();
else
  self:Show();
end;


Thanks a lot for your help, Aanson.

Best wishes

lemmi

Phanx 02-07-12 10:03 PM

Doesn't Recount already have an option for this? Turn off data collection for everything except party and raid if you haven't already (since you obviously don't care about such data) and then turn on "hide when not collecting".

lemmi13 02-08-12 10:28 AM

Quote:

Originally Posted by Phanx (Post 252265)
Doesn't Recount already have an option for this? Turn off data collection for everything except party and raid if you haven't already (since you obviously don't care about such data) and then turn on "hide when not collecting".

Yes, but to be honest - i got stucked to the config options at Recount. :confused:

griffulas 07-18-12 07:45 AM

Im trying to create a similar panel, but id like it show in raid/party and have a chat tap with it so raid and party chat will show with a panel behind it about my main chat window

Aanson 07-22-12 03:22 AM

Quote:

Originally Posted by griffulas (Post 258375)
Im trying to create a similar panel, but id like it show in raid/party and have a chat tap with it so raid and party chat will show with a panel behind it about my main chat window

Yeah, that's pretty easily achievable. If you've not done so already, create a new chat window and use settings to pick Raid Chat. Same for Party Chat.

Then, the following code can be used (assuming you're also using kgPanels):

OnLoad
Lua Code:
  1. self:RegisterEvent("PARTY_MEMBERS_CHANGED")
  2. self:RegisterEvent("RAID_ROSTER_UPDATE")
  3. Recount.MainWindow:SetParent(self)

OnEvent
Lua Code:
  1. local pmems = GetNumPartyMembers()
  2. local rmems = GetNumRaidMembers()
  3. if (pmems < 1 and rmems < 1) then -- you're neither in a party or a raid
  4.   self:Hide()
  5.   ChatFrame1Tab:Click("LeftButton") -- you're using your standard chat
  6. elseif (pmems >= 1 or rmems >= 1) then -- it knows it needs to do something
  7.   self:Show() -- you're panel (and Recount) shows
  8.   if pmems >= 1 then -- you're in a party
  9.     ChatFrame3Tab:Click("LeftButton") -- (provided ChatFrame3 shows Party Chat)
  10.   elseif rmems >= 1 then -- you're in a raid (or a party has been converted to raid)
  11.     ChatFrame4Tab:Click("LeftButton") -- (provided ChatFrame4 shows Raid Chat)
  12.   end
  13. end

This can also be achieved by registering / unregistering to/from Party Chat or Raid chat and using the same ChatFrame (ie ChatFrame1 or ChatFrame3) but I personally think that the above method is the cleanest and most effective solution.


All times are GMT -6. The time now is 02:50 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI