Quantcast
Group frames don't respond to OnShow/OnHide? - WoWInterface
Thread Tools Display Modes
07-05-17, 03:19 AM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 356
Group frames don't respond to OnShow/OnHide?

Hi all,

It's been a while since I posted my last oUF related thread here

So, I'm currently spawning my raid group frames like the following:

Lua Code:
  1. local koverwatch = LSM:Fetch("font", "koverwatch");
  2.  
  3. for i = 1, NUM_RAID_GROUPS do
  4.     local overrideName = "Raid" .. i;
  5.  
  6.     width = db.raid.width;
  7.     height = db.raid.height;
  8.     point, relativeFrame, relativePoint, ofsx, ofsy = unpack(db.raid.position);
  9.    
  10.     if i >= 2 then
  11.         ofsx = ofsx + ((width + 3) * ((i - 1) % 4));
  12.     end
  13.  
  14.     if i >= 5 then
  15.         ofsy = ofsy + (height + 3) * 5 + 28;
  16.     end
  17.  
  18.     local group = self:SpawnHeader(
  19.         overrideName,
  20.         nil,
  21.         "custom [group:raid] show; hide",
  22.         -- attributes
  23.         "oUF-initialConfigFunction", ("self:SetWidth(%d); self:SetHeight(%d);"):format(width, height),
  24.         "showRaid", true,
  25.         "showParty", false,
  26.         "showPlayer", true,
  27.         "showSolo", false,
  28.         "groupFilter", tostring(i),
  29.         "point", "LEFT",
  30.         -- "xOffset", ,
  31.         -- "yOffset", ,
  32.         "maxColumns", 5,
  33.         "unitsPerColumn", 1,
  34.         "columnSpacing", 8,
  35.         "columnAnchorPoint", "TOP"
  36.     );
  37.     group:SetPoint(point, relativeFrame, relativePoint, ofsx, ofsy);
  38.     group:SetScript("OnShow", function(self)
  39.         self.headText:Show();
  40.     end);
  41.     group:SetScript("OnHide", function(self)
  42.         self.headText:Hide();
  43.     end);
  44.  
  45.     local headText = group:CreateFontString("$parentHeadText", "OVERLAY");
  46.     headText:SetFont(koverwatch, 14, "OUTLINE");
  47.     headText:SetPoint("BOTTOM", group, "TOP");
  48.     headText:SetText("Group " .. i);
  49.     headText:Hide();
  50.  
  51.     group.headText = headText;
  52. end

I'm currently trying to display a text, "Group N", on top of each group's frame, but it seems like those frames don't call OnShow/OnHide scripts

So, I've tested it without headText being hidden on creation and here's what it looks like at the moment.



From "Group 1" to "Group 7" are properly positioned while "Group 8" is off...

So, my conclusion here is that each of groups are created and already visible since I'm in raid group (and that's why it's not calling OnShow/OnHide scripts), but are not yet sized correctly until that particular group gets a member in it and that's why it's causing this.

However, I'm still unsure of how I could fix this

Any helps, please?!

Thank you!!

Last edited by Layback_ : 07-05-17 at 03:21 AM.
  Reply With Quote
07-05-17, 11:45 PM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,699
First off, it's good practice to use HookScript instead of SetScript when adding script handlers to a foreign object, to avoid overriding the original script handler.

As for the issue, try HookScript "OnAttributeChanged" and check for the amount of players in the given group.
The visibility that you're trying to check for is always going to be true while you're in a raid, according to your visibility conditions "custom [group:raid] show; hide".
  Reply With Quote
07-06-17, 03:44 AM   #3
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 356
Hi p3lim,

Originally Posted by p3lim View Post
First off, it's good practice to use HookScript instead of SetScript when adding script handlers to a foreign object, to avoid overriding the original script handler.
Thank you for correcting me

I definitely didn't consider such cases..

Originally Posted by p3lim View Post
As for the issue, try HookScript "OnAttributeChanged" and check for the amount of players in the given group.
The visibility that you're trying to check for is always going to be true while you're in a raid, according to your visibility conditions "custom [group:raid] show; hide".
You are right, again.

I forgot that I assigned "custom [group:raid] show; hide" for visibility which will always show each header frame while I'm in raid group as you said

Had a go with "OnAttributeChanged" script, but eeh... doesn't seem like it.

There were some attributes like "statehidden", "childN", "_ignore" and "frameref-childN" where I thought "childN" attribute would be the one that I should be dealing with, but it wasn't..

Thus, I'm guessing that the best option would be changing visibility condition, although I'm still unsure tho...

(Maybe I should have a look at macro conditionals )
  Reply With Quote
07-06-17, 11:50 PM   #4
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,699
You could try parenting the header text to the top member of each group, voids the check completely.
  Reply With Quote
07-13-17, 10:03 PM   #5
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 356
Originally Posted by p3lim View Post
You could try parenting the header text to the top member of each group, voids the check completely.
It worked !!

Thanks a lot!!
  Reply With Quote
07-26-17, 08:17 PM   #6
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 356
One more question!

What would be the best way to get access (or get reference) to first member frame of the group?

I'm currently doing it this way.

Lua Code:
  1. -- string comparison to see if the current frame is the first member frame of the group
  2. -- e.g. MyUI_Raid1UnitButton1
  3. if E:StringEndsWith(frame:GetName(), "1") then
  4.     -- get parent
  5.     local group = frame:GetParent();
  6. end

This would work fine, but I am curious if there is any better solution to achieve this.

Last edited by Layback_ : 07-26-17 at 08:21 PM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Group frames don't respond to OnShow/OnHide?

Thread Tools
Display Modes

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