WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Target subframe within main frame (https://www.wowinterface.com/forums/showthread.php?t=57026)

wille480 02-24-19 02:12 PM

Target subframe within main frame
 
Hello! So i am wondering how i can target the subframe that lies within a mainframe? I am making a group box sort of where the main window is just the window where the group members lies inside.

This is how it looks: https://gyazo.com/1bf04b61fb48f560429fadf1f944f10e

How can i target the frame with the name "Lwarlock"?


How my code is built
Lua Code:
  1. local mainWindow = CreateFrame("Frame", "DragFrame", UIParent) -- The main window (Orange color)
  2.    
  3.     local subFrame = CreateFrame("Frame", "SUBFRAME", UIParent)
  4.     local texture = subFrame:CreateTexture("ARTWORK")
  5.     local fontString = subFrame:CreateFontString(nil. "OVERLAY", "GameFontNormal")
  6.  
  7.     subFrame:SetPoint("TOP", mainWindow, "TOP", 0,0)

A general way how the code looks. That is the way i add the subframe to the main frame anyways. Sub frames are going to be added and removed left and right in this program so this is why i cant use a frame:SetScript("OnMouseDown") event. That is what i think atleast, i have this subframe creation code inside a function that will be called pretty often so! Any tips? Kind Regards

Fizzlemizz 02-24-19 04:24 PM

Something to look at and play with. A function to uniformly create all sub-frames (buttons in this case) with the return value being stored in a table attached to the main frame. Not the only way.

Lua Code:
  1. local function CreateSubFrame(self)
  2.     local f = CreateFrame("Button", "$parentSUBFRAME"..#self.SubFrames+1, self)
  3.     f:SetSize(self:GetSize())
  4.     f.texture = f:CreateTexture("ARTWORK")
  5.     f.texture:SetAllPoints()
  6.     f.texture:SetTexture("Interface/BUTTONS/WHITE8X8")
  7.     f.texture:SetVertexColor(0.3, 0.3, 0.3, 0.5)
  8.     f.text = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  9.     f.text:SetPoint("CENTER")
  10.     f.text:SetText(f:GetName())
  11.     local p
  12.     if #self.SubFrames == 0 then
  13.         p = self
  14.     else
  15.         p = self.SubFrames[#self.SubFrames]
  16.     end
  17.     f:SetPoint("TOP", p, "BOTTOM", 0, -5)
  18.     f:SetScript("OnEnter", function(self)
  19.         f.texture:SetVertexColor(0.6, 0.6, 0.6, 0.5)
  20.     end)
  21.     f:SetScript("OnLeave", function(self)
  22.         f.texture:SetVertexColor(0.3, 0.3, 0.3, 0.5)
  23.     end)
  24.     f:SetScript("OnClick", function(self)
  25.         print(self:GetName().." Clicked!!!!")
  26.     end)
  27.     return f
  28. end
  29.  
  30. local mainWindow = CreateFrame("Frame", "wille480DragFrame", UIParent) -- The main window (Orange color)
  31. mainWindow:SetSize(200, 20)
  32. mainWindow:SetPoint("CENTER")
  33. mainWindow.SubFrames = {}
  34.  
  35. for i= 1, 5 do
  36.     tinsert(mainWindow.SubFrames, CreateSubFrame(mainWindow))
  37. end

Frame names are global so you should try and make them unique, hence the addition of "wille480" to "DragFrame"

wille480 02-24-19 05:22 PM

Quote:

Originally Posted by Fizzlemizz (Post 331580)
Something to look at and play with. A function to uniformly create all sub-frames (buttons in this case) with the return value being stored in a table attached to the main frame. Not the only way.

Lua Code:
  1. local function CreateSubFrame(self)
  2.     local f = CreateFrame("Button", "$parentSUBFRAME"..#self.SubFrames+1, self)
  3.     f:SetSize(self:GetSize())
  4.     f.texture = f:CreateTexture("ARTWORK")
  5.     f.texture:SetAllPoints()
  6.     f.texture:SetTexture("Interface/BUTTONS/WHITE8X8")
  7.     f.texture:SetVertexColor(0.3, 0.3, 0.3, 0.5)
  8.     f.text = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  9.     f.text:SetPoint("CENTER")
  10.     f.text:SetText(f:GetName())
  11.     local p
  12.     if #self.SubFrames == 0 then
  13.         p = self
  14.     else
  15.         p = self.SubFrames[#self.SubFrames]
  16.     end
  17.     f:SetPoint("TOP", p, "BOTTOM", 0, -5)
  18.     f:SetScript("OnEnter", function(self)
  19.         f.texture:SetVertexColor(0.6, 0.6, 0.6, 0.5)
  20.     end)
  21.     f:SetScript("OnLeave", function(self)
  22.         f.texture:SetVertexColor(0.3, 0.3, 0.3, 0.5)
  23.     end)
  24.     f:SetScript("OnClick", function(self)
  25.         print(self:GetName().." Clicked!!!!")
  26.     end)
  27.     return f
  28. end
  29.  
  30. local mainWindow = CreateFrame("Frame", "wille480DragFrame", UIParent) -- The main window (Orange color)
  31. mainWindow:SetSize(200, 20)
  32. mainWindow:SetPoint("CENTER")
  33. mainWindow.SubFrames = {}
  34.  
  35. for i= 1, 5 do
  36.     tinsert(mainWindow.SubFrames, CreateSubFrame(mainWindow))
  37. end

Frame names are global so you should try and make them unique, hence the addition of "wille480" to "DragFrame"

Wow, nice solution! Tweaked it abit for my likeing =) . Appriciate the help, kinda new to addon programming, made an addon before "HelyaAssist" but trying to learn a new skill as university times are short now! ty for help


All times are GMT -6. The time now is 03:40 PM.

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