Quantcast Target subframe within main frame - WoWInterface
Thread Tools Display Modes
02-24-19, 02:12 PM   #1
wille480
A Wyrmkin Dreamwalker
Join Date: Jan 2017
Posts: 56
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

Last edited by wille480 : 02-24-19 at 02:17 PM.
  Reply With Quote
02-24-19, 04:24 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,006
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"
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-24-19 at 04:30 PM.
  Reply With Quote
02-24-19, 05:22 PM   #3
wille480
A Wyrmkin Dreamwalker
Join Date: Jan 2017
Posts: 56
Originally Posted by Fizzlemizz View Post
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
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Target subframe within main frame

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