WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Group frames don't respond to OnShow/OnHide? (https://www.wowinterface.com/forums/showthread.php?t=55546)

Layback_ 07-05-17 03:19 AM

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 :confused:

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!!

p3lim 07-05-17 11:45 PM

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".

Layback_ 07-06-17 03:44 AM

Hi p3lim,

Quote:

Originally Posted by p3lim (Post 324107)
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..

Quote:

Originally Posted by p3lim (Post 324107)
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 :p)

p3lim 07-06-17 11:50 PM

You could try parenting the header text to the top member of each group, voids the check completely.

Layback_ 07-13-17 10:03 PM

Quote:

Originally Posted by p3lim (Post 324126)
You could try parenting the header text to the top member of each group, voids the check completely.

It worked :banana:!!

Thanks a lot!!

Layback_ 07-26-17 08:17 PM

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.


All times are GMT -6. The time now is 11:47 PM.

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