WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Is there a way to determine raid group number with macro conditional? (https://www.wowinterface.com/forums/showthread.php?t=55754)

Layback_ 09-20-17 09:22 PM

Is there a way to determine raid group number with macro conditional?
 
Hi all,

I am using an oUF to spawn my raid frames, but since this is more like generic WoW Lua related question, I've decided to post it here :p

So, oUF uses macro conditional to decide whether it should display raid frames or not and here's my current setting(?).

Code:

for i = 1, NUM_RAID_GROUPS do
        local group = self:SpawnHeader(
                overrideName,
                nil,
                "custom [group:raid] show; hide",
                -- attributes
                "oUF-initialConfigFunction", ("self:SetWidth(%d); self:SetHeight(%d);"):format(width, height),
                "showRaid", true,
                "showParty", false,
                "showPlayer", true,
                "showSolo", false,
                "groupFilter", tostring(i),
                "point", "LEFT",
                -- "xOffset", ,
                -- "yOffset", ,
                "maxColumns", 5,
                "unitsPerColumn", 1,
                "columnSpacing", 3,
                "columnAnchorPoint", "TOP"
        );
end

At the moment, this sets all 8 raid groups' visibility to true as long as I'm in a raid (even if there is no group member in a particular group).

My question is would it be possible to write a macro conditional to:

"Show this raid group if there is at least a single member in that specific group, otherwise hide"

Thanks in advance!!

kurapica.igas 09-21-17 10:46 PM

Since unit id can't tell which group it's in, so I don't think that'd be done with macro condition.

Don't know how ouf handle this, I have secure codes to resize the whole panel and re-position unit frames based on their visibility, so the panel will keep 0-width, 0-height if there is no unit in it.

The key is using SecureHandlerWrapScript.

Layback_ 09-22-17 03:56 AM

Quote:

Originally Posted by kurapica.igas (Post 325235)
Since unit id can't tell which group it's in, so I don't think that'd be done with macro condition.

Don't know how ouf handle this, I have secure codes to resize the whole panel and re-position unit frames based on their visibility, so the panel will keep 0-width, 0-height if there is no unit in it.

The key is using SecureHandlerWrapScript.

Hi kurapica,

Thanks for a hint!

I'll have a look at SecureHandlerWrapScript and see how I go :D

*EDIT

hm.... there's not many info about SecureHandlerWrapScript even on Wowpedia...

Could you please give me some example on how this function works?

Thank you!

kurapica.igas 09-22-17 05:06 AM

My codes is here, it's an interface so I used it for raid panel and bag containers.

Here is a simple one, I don't do a test, since the group header settings is ignored :

Lua Code:
  1. local panel = CreateFrame("Frame", "ResizablePanel", UIParent, "SecureFrameTemplate")
  2.  
  3. -- Shortcut
  4. panel.Execute = SecureHandlerExecute
  5. panel.SetFrameRef = SecureHandlerSetFrameRef
  6. panel.WrapScript = function (self, frame, script, preBody, postBody)
  7.     SecureHandlerWrapScript(frame, script, self, preBody, postBody)
  8. end
  9.  
  10. -- Grid Settings
  11. panel:SetAttribute("WIDTH", 100)    -- Unit Frame width
  12. panel:SetAttribute("HEIGHT", 48)    -- Unit Frame height
  13. panel:SetAttribute("HSPACE", 2)     -- horizontal spacing
  14. panel:SetAttribute("VSPACE", 2)     -- vertical spacing
  15. panel:SetAttribute("ROWCNT", 5)     -- Row counts
  16. panel:SetAttribute("COLCNT", 4)     -- Col counts
  17.  
  18. panel:Execute[[
  19.     Manager = self  -- keep self to avoid some bug, I don't know if it still existed
  20.  
  21.     _UnitFrames = newtable()  -- where we keep all unit frames
  22.  
  23.     UpdatePanelSize = [=[
  24.         -- For simple, skip several settings like margin, orientation
  25.         local rowcnt = Manager:GetAttribute("ROWCNT")
  26.         local colcnt = Manager:GetAttribute("COLCNT")
  27.         local width  = Manager:GetAttribute("WIDTH")
  28.         local height = Manager:GetAttribute("HEIGHT")
  29.         local vspace = Manager:GetAttribute("VSPACE")
  30.         local hspace = Manager:GetAttribute("HSPACE")
  31.  
  32.         local count  = 0
  33.  
  34.         -- Re-position unit frames based on visiblity
  35.         for i = 1, #_UnitFrames do
  36.             local frm = _UnitFrames[i]
  37.             if frm:IsShown() then
  38.                 -- orientation is vertical first
  39.                 local posX = (floor(count / rowcnt)) * (width + hspace)
  40.                 local posY = (count % rowcnt) * (height + vspace)
  41.  
  42.                 frm:SetWidth(width)
  43.                 frm:SetHeight(height)
  44.                 frm:ClearAllPoints()
  45.        
  46.                 -- from top to bottom
  47.                 frm:SetPoint("TOP", Manager, "TOP", 0, - posY)
  48.  
  49.                 -- from left to right
  50.                 frm:SetPoint("LEFT", Manager, "LEFT", posX, 0)
  51.  
  52.                 count = count + 1
  53.             end
  54.         end
  55.  
  56.         -- Re-size the Manager
  57.         local maxcol = ceil(count / rowcnt)
  58.         local maxrow = maxcol == 1 and count or rowcnt
  59.  
  60.         if maxrow > 0 and maxcol > 0 then
  61.             Manager:SetWidth(maxcol * width + (maxcol - 1) * hspace)
  62.             Manager:SetHeight(maxrow * height + (maxrow - 1) * vspace)
  63.         else
  64.             -- You also can use Hide here
  65.             Manager:SetWidth(1)
  66.             Manager:SetHeight(1)
  67.         end
  68.     ]=]
  69. ]]
  70.  
  71. -- For simple I generate those unit frames directly
  72. -- Your is generated by the ouf
  73. for i = 1, panel:GetAttribute("ROWCNT") do
  74.     for j = i , panel:GetAttribute("COLCNT") do
  75.         local unitframe = CreateFrame("Button", "ResizablePanel_" .. i .. "_" .. j, panel, "SecureActionButtonTemplate")
  76.        
  77.         -- Register the unitframe
  78.         panel:SetFrameRef("unitframe", unitframe)
  79.         panel:Execute[[tinsert(_UnitFrames, Manager:GetFrameRef("unitframe"))]]
  80.  
  81.         -- Wrap the unitframe's show/hide
  82.         -- So the secure UpdatePanelSize can be run based on the unitframe's visiblity
  83.         panel:WrapScript(unitframe, "OnShow", [[Manager:RunFor(self, UpdatePanelSize)]])
  84.         panel:WrapScript(unitframe, "OnHide", [[Manager:RunFor(self, UpdatePanelSize)]])
  85.     end
  86. end
  87.  
  88. -- Force updating
  89. Manager:Execute[[Manager:Run(UpdatePanelSize)]]

Also there is a topic discuss about Run secure code based on the group header system, you can find my answer from #12.

I don't know if it can be combined with the Ouf, you may have a try.

kurapica.igas 09-22-17 05:53 AM

And about the wrapscript, you'd better have a look at the SecureHandlers, it's a little like the HookScript, but there are two secure snippets, prebody before the real script handler, and a postbody after that.

The snippets are running in the manager's environment not the target frames, so I can use variables like Manager in those snippets, that's the main reason why I use it, so I can manage all unit frames on all panels in one Manager's environment.

You can find the variables for each script type in that file. The prebody may return two values, the first determine whether the real script handler would be run(also the postbody), the second is a message, if the message existed then the postbody would be called after the real script handler. As an example, I can swap two button's action after clicking one of them.

Layback_ 09-23-17 04:08 PM

Hi again kurapica,

sorry for a late response.

Hm...... guess I got the concept, but still need some practice to fully understand it :rolleyes:

Thank you for a detailed explanation!


All times are GMT -6. The time now is 10:58 AM.

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