Quantcast
New author requiring some help - WoWInterface
Thread Tools Display Modes
07-08-13, 05:24 AM   #1
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
New author requiring some help

I should preface this by saying that I have no training in coding other then that from High School.
So please excuse my silly questions. Found this code thanks to Xchg of Silvermoon on http://us.battle.net/wow/en/forum/topic/1305771013

My question is what parts do I need to change so that I can individualize each set of Scroll Frames. As Im going to have Multiple Sets of Frames one for each capital City.


Code:
-- -- -- -- -- -- -- -- -- Find Menu Scroll Stormwind -- -- -- -- -- -- -- -- --
--parent frame 
local frame = CreateFrame("Frame", "FindMenuScrollStormwind", FindMenu) 
frame:SetSize(385, 150) 
frame:SetPoint("CENTER", 0,15) -- Useing this setpoint you can move the Frame indepently of the Scroll Bar
local texture = frame:CreateTexture() 
texture:SetAllPoints() 
texture:SetTexture(0,0,0,0) 
frame.background = texture 

--scrollframe 
scrollframe = CreateFrame("ScrollFrame", nil, frame) 
scrollframe:SetPoint("TOPLEFT", 0, 0) 
scrollframe:SetPoint("BOTTOMRIGHT", 0, 0) 
local texture = scrollframe:CreateTexture() 
texture:SetAllPoints() 
texture:SetTexture(0,0,0,0) 
frame.scrollframe = scrollframe 

--scrollbar 
scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate") 
scrollbar:SetPoint("TOPLEFT", frame, "TOPRIGHT", 3, -23) -- This Moves the Up Arrow on the Scroll Bar
scrollbar:SetPoint("BOTTOMLEFT", frame, "BOTTOMRIGHT", 0, -23) -- This Moves the Down Arrow on the Scoll Bar
scrollbar:SetMinMaxValues(1, 200) 
scrollbar:SetValueStep(1) 
scrollbar.scrollStep = 1 
scrollbar:SetValue(0) 
scrollbar:SetWidth(15)
scrollbar:SetScript("OnValueChanged", 
function (self, value) 
self:GetParent():SetVerticalScroll(value) 
end) 
local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") 
scrollbg:SetAllPoints(scrollbar) 
scrollbg:SetTexture(0, 0, 0, 0.4) 
frame.scrollbar = scrollbar 

--content frame 
local content = CreateFrame("Frame", nil, scrollframe) 
content:SetSize(128, 128) 
--local texture = content:CreateTexture() 
--texture:SetAllPoints() 
--texture:SetTexture("Interface\\GLUES\\MainMenu\\Glues-BlizzardLogo") 
--content.texture = texture 
scrollframe.content = content 

scrollframe:SetScrollChild(content)

-- Find Menu Options Buttons

--local button = CreateFrame("Button", "ButtonName", Parentframe,"UIPanelButtonTemplate")
--ButtonName:SetText("My Name is Button")
--ButtonName:SetPoint("point", "releventframe", "relativePoint", offsetx,offsety)
--ButtonName:SetWidth(110)
--ButtonName:SetHeight(50)

local button = CreateFrame("Button", "Battle_Pet_Trainer",content,"UIPanelButtonTemplate") -- Row 1 Column 1
Battle_Pet_Trainer:SetText("Battle Pet Trainer")
Battle_Pet_Trainer:SetPoint("TOPLEFT",0,0)
Battle_Pet_Trainer:SetWidth(120)
Battle_Pet_Trainer:SetHeight(50)

local button = CreateFrame("Button", "Reforge",content,"UIPanelButtonTemplate") -- Row 1 Column 2
Reforge:SetText("Reforge")
Reforge:SetPoint("LEFT", "Battle_Pet_Trainer", "RIGHT", 0,0)
Reforge:SetWidth(120)
Reforge:SetHeight(50)

local button = CreateFrame("Button", "Transmogrification",content,"UIPanelButtonTemplate") -- Row 1 Column 3
Transmogrification:SetText("Transmogrification")
Transmogrification:SetPoint("LEFT", "Reforge", "RIGHT", 0,0)
Transmogrification:SetWidth(120)
Transmogrification:SetHeight(50)

local button = CreateFrame("Button", "Void_Storage",content,"UIPanelButtonTemplate") -- Row 2 Column 1
Void_Storage:SetText("Void Storage")
Void_Storage:SetPoint("TOP", "Battle_Pet_Trainer", "BOTTOM", 0,0)
Void_Storage:SetWidth(120)
Void_Storage:SetHeight(50)

local button = CreateFrame("Button", "Auction_House",content,"UIPanelButtonTemplate") -- Row 2 Column 2
Auction_House:SetText("Auction House")
Auction_House:SetPoint("TOP", "Reforge", "BOTTOM", 0,0)
Auction_House:SetWidth(120)
Auction_House:SetHeight(50)

local button = CreateFrame("Button", "Bank",content,"UIPanelButtonTemplate") -- Row 2 Column 3
Bank:SetText("Bank")
Bank:SetPoint("TOP", "Transmogrification", "BOTTOM", 0,0)
Bank:SetWidth(120)
Bank:SetHeight(50)

local button = CreateFrame("Button", "Barber",content,"UIPanelButtonTemplate") -- Row 3 Column 1
Barber:SetText("Barber")
Barber:SetPoint("TOP", "Void_Storage", "BOTTOM", 0,0)
Barber:SetWidth(120)
Barber:SetHeight(50)

local button = CreateFrame("Button", "Class_Trainer",content,"UIPanelButtonTemplate") -- Row 3 Column 2
Class_Trainer:SetText("Class Trainer")
Class_Trainer:SetPoint("TOP", "Auction_House", "BOTTOM", 0,0)
Class_Trainer:SetWidth(120)
Class_Trainer:SetHeight(50)

local button = CreateFrame("Button", "Flight_Master",content,"UIPanelButtonTemplate") -- Row 3 Column 3
Flight_Master:SetText("Flight Master")
Flight_Master:SetPoint("TOP", "Bank", "BOTTOM", 0,0)
Flight_Master:SetWidth(120)
Flight_Master:SetHeight(50)

local button = CreateFrame("Button", "Guild_Master",content,"UIPanelButtonTemplate") -- Row 4 Column 1
Guild_Master:SetText("Guild Master")
Guild_Master:SetPoint("TOP", "Barber", "BOTTOM", 0,0)
Guild_Master:SetWidth(120)
Guild_Master:SetHeight(50)

local button = CreateFrame("Button", "Inn",content,"UIPanelButtonTemplate") -- Row 4 Column 2
Inn:SetText("Inn")
Inn:SetPoint("TOP", "Class_Trainer", "BOTTOM", 0,0)
Inn:SetWidth(120)
Inn:SetHeight(50)

local button = CreateFrame("Button", "MailBox",content,"UIPanelButtonTemplate") -- Row 4 Column 3
MailBox:SetText("MailBox")
MailBox:SetPoint("TOP", "Flight_Master", "BOTTOM", 0,0)
MailBox:SetWidth(120)
MailBox:SetHeight(50)

local button = CreateFrame("Button", "Points_of_Interest",content,"UIPanelButtonTemplate") -- Row 5 Column 1
Points_of_Interest:SetText("Points of Interest")
Points_of_Interest:SetPoint("TOP", "Guild_Master", "BOTTOM", 0,0)
Points_of_Interest:SetWidth(120)
Points_of_Interest:SetHeight(50)

local button = CreateFrame("Button", "Portals",content,"UIPanelButtonTemplate") -- Row 5 Column 2
Portals:SetText("Portals")
Portals:SetPoint("TOP", "Inn", "BOTTOM", 0,0)
Portals:SetWidth(120)
Portals:SetHeight(50)

local button = CreateFrame("Button", "Profession_Trainer",content,"UIPanelButtonTemplate") -- Row 5 Column 3
Profession_Trainer:SetText("Profession Trainer")
Profession_Trainer:SetPoint("TOP", "MailBox", "BOTTOM", 0,0)
Profession_Trainer:SetWidth(120)
Profession_Trainer:SetHeight(50)

local button = CreateFrame("Button", "Stable_Master",content,"UIPanelButtonTemplate") -- Row 6 Column 1
Stable_Master:SetText("Stable Master")
Stable_Master:SetPoint("TOP", "Points_of_Interest", "BOTTOM", 0,0)
Stable_Master:SetWidth(120)
Stable_Master:SetHeight(50)

local button = CreateFrame("Button", "Vendor",content,"UIPanelButtonTemplate") -- Row 6 Column 2
Vendor:SetText("Vendor")
Vendor:SetPoint("TOP", "Portals", "BOTTOM", 0,0)
Vendor:SetWidth(120)
Vendor:SetHeight(50)
  Reply With Quote
07-08-13, 12:12 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,795
First of all, you gave many of your frames/objects very generic global names. This is not good practice, as you're likely to break something (or your addon will be broken by something else). Either skip the global name reference entirely, or make it much more descriptive/specific to your addon.

Secondly, may I ask *why* you need different scroll frames for each city rather than reusing just one of them?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-08-13, 01:52 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,991
You have global leaks at the following lines. A global leak is when a variable that is meant to be local is not defined as such and its value "leaks" into the global environment. Note you only need to define a variable as a local once. From then on, Lua will recognize it as a local variable.
Code:
--scrollframe 
local scrollframe = CreateFrame("ScrollFrame", nil, frame)
Code:
--scrollbar 
local scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate")




Code:
local button = CreateFrame("Button", "ButtonName", Parentframe,"UIPanelButtonTemplate")
ButtonName:SetText("My Name is Button")
ButtonName:SetPoint("point", "releventframe", "relativePoint", offsetx,offsety)
ButtonName:SetWidth(110)
ButtonName:SetHeight(50)
The template you used for the buttons at the bottom of your code is one of the worst ways to do this. You're assigning the frame returned by CreateFrame() to a local and never using it. It would be better to use the local instead of referencing the global environment by the frame's name.

This is also where the problem with the frame's name being generic is as pointed out by Seerah. When 2 frames with the same name are created by CreateFrame(), it creates and returns each frame individually as expected, but only the first frame will be stored in the global environment. When using this method of setting up your button, you will not only lose access to the button you had created, but also corrupt whatever frame was stored in said global. In some cases, if the stored frame is of a different frame type than what you had created, you may run into Attempt to call nil errors when using type-specific functions.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-08-13 at 01:54 PM.
  Reply With Quote
07-08-13, 04:28 PM   #4
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
I think I understand what you mean, Would this be a correction for that

Code:
Battle_Pet_Trainer_Stormwind = CreateFrame("Button", "Battle_Pet_Trainer_Stormwind",content,"UIPanelButtonTemplate") -- Row 1 Column 1
Battle_Pet_Trainer_Stormwind:SetText("Battle Pet Trainer")
Battle_Pet_Trainer_Stormwind:SetPoint("TOPLEFT",0,0)
Battle_Pet_Trainer_Stormwind:SetWidth(120)
Battle_Pet_Trainer_Stormwind:SetHeight(50)
  Reply With Quote
07-08-13, 04:32 PM   #5
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
I have seen excellent use of a database by gmarco in his RemGank mod, I dont really understand how to do it.

I know that would be a better option for what im doing, I just really dont know how to program correctly.
  Reply With Quote
07-08-13, 04:43 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Yksrep View Post
I think I understand what you mean, Would this be a correction for that

Code:
Battle_Pet_Trainer_Stormwind = CreateFrame("Button", "Battle_Pet_Trainer_Stormwind",content,"UIPanelButtonTemplate") -- Row 1 Column 1
Battle_Pet_Trainer_Stormwind:SetText("Battle Pet Trainer")
Battle_Pet_Trainer_Stormwind:SetPoint("TOPLEFT",0,0)
Battle_Pet_Trainer_Stormwind:SetWidth(120)
Battle_Pet_Trainer_Stormwind:SetHeight(50)

That's a better global name, but it is still too generic -- it should include your addon's name so it is immediately obvious which addon created it -- and you are still using a slow global reference instead of a faster local one.

Code:
local button = CreateFrame("Button", "MyAddonStormwindBattlePetTrainer", content, "UIPanelButtonTemplate") -- Row 1 Column 1
button:SetText("Battle Pet Trainer")
button:SetPoint("TOPLEFT",0,0)
button:SetWidth(120)
button:SetHeight(50)
Also, as someone earlier in the thread mentioned, since you're only ever going to be showing buttons for one city at a time, you should just use a single frame, and update it according to which city you're in, instead of creating a separate frame for every city.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
07-08-13, 06:40 PM   #7
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Originally Posted by Phanx View Post

Also, as someone earlier in the thread mentioned, since you're only ever going to be showing buttons for one city at a time, you should just use a single frame, and update it according to which city you're in, instead of creating a separate frame for every city.
That's not strictly how I intend it to work. I intend the user to be able to select which city they want to go to. However I get what you mean, I can set it up for on CityselectStormwind button (for example) to Show the relevant buttons associated with Stormwind in the Scroll Frame. Is that what you mean?

On another note does anyone know a good reference to a working example of how to pull buttons from a database (similar to how gmacro did his). Or wold it be better to just register that once the city is selected it displays the buttons from another lua.
  Reply With Quote
07-08-13, 09:01 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Yksrep View Post
I intend the user to be able to select which city they want to go to. However I get what you mean, I can set it up for on CityselectStormwind button (for example) to Show the relevant buttons associated with Stormwind in the Scroll Frame. Is that what you mean?
Yes. It doesn't matter which conditions cause the contents of the frame to change. If you're only ever going to show Contents A or Contents B (never both at the same time) then you should only create one frame, and change the contents as needed.

Originally Posted by Yksrep View Post
On another note does anyone know a good reference to a working example of how to pull buttons from a database (similar to how gmacro did his).
You can't store buttons (or other frame objects) in a database (which is really just a table) between sessions. You can store data (such as lists of things you want to show buttons for) in a table, and then create buttons based on what's in the table:

Code:
-- Table describing the buttons you want to create:
local buttonData = {
	{
		text = "Button A",
		click = function(self, mouseButton)
			print("You clicked Button A!")
		end,
	},
	{
		text = "Button B",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
}

-- Table to hold the actual button objects:
local buttons = {}

-- Create the container frame:
local frame = CreateFrame("Frame", "MyParentFrame", UIParent)
frame:SetPoint("TOP", UIParent, 0, -300)
frame:SetSize(200, 20)

-- Give it a background:
local backdrop = frame:CreateTexture(nil, "BACKDROP")
backdrop:SetAllPoints(true)
backdrop:SetTexture(0, 0, 0, 0.5)

-- Loop over the data list:
for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "MyButton"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 1 then
		-- ...anchor the button to the container:
		button:SetPoint("TOP", frame, "BOTTOM", 0, -5)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end

-- Now your "buttons" table looks like this:
-- buttons = {
-- 	[1] = <button object named "MyButton1">,
-- 	[2] = <button object named "MyButton2">,
-- }
Also, since this data is static (eg. you're not asking the user to define their own list of buttons) it should just be stored in your addon, not in a "database" (a table stored between sessions in your addon's SavedVariables).

For an example of how to store user data (such as option settings) between sessions, see:
http://www.wowpedia.org/Saving_varia..._game_sessions
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.

Last edited by Phanx : 07-09-13 at 02:54 AM.
  Reply With Quote
07-08-13, 09:27 PM   #9
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Thanks Phanx your help is greatly appreciated.
  Reply With Quote
07-08-13, 09:44 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,991
Originally Posted by Yksrep View Post
I think I understand what you mean, Would this be a correction for that

Code:
Battle_Pet_Trainer_Stormwind = CreateFrame("Button", "Battle_Pet_Trainer_Stormwind",content,"UIPanelButtonTemplate") -- Row 1 Column 1
Battle_Pet_Trainer_Stormwind:SetText("Battle Pet Trainer")
Battle_Pet_Trainer_Stormwind:SetPoint("TOPLEFT",0,0)
Battle_Pet_Trainer_Stormwind:SetWidth(120)
Battle_Pet_Trainer_Stormwind:SetHeight(50)
The first line has a redundancy in it. Since CreateFrame() already sets the global, you don't need to set it again with the return from the function, which is the same frame. I marked the unnecessary part of the line that should be removed in red.

However, I was suggesting you phase out the use of the globals and use the local you were creating instead. This would be as Phanx suggested.
Originally Posted by Phanx View Post
That's a better global name, but it is still too generic -- it should include your addon's name so it is immediately obvious which addon created it -- and you are still using a slow global reference instead of a faster local one.

Code:
local button = CreateFrame("Button", "MyAddonStormwindBattlePetTrainer", content, "UIPanelButtonTemplate") -- Row 1 Column 1
button:SetText("Battle Pet Trainer")
button:SetPoint("TOPLEFT",0,0)
button:SetWidth(120)
button:SetHeight(50)
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
07-08-13, 11:00 PM   #11
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Phantom I have done exactly that, it's made it easier to make the buttons.

Phanx in regard to your table code from what I understand it should be showing both buttons. I the minor change to

Code:
-- Table to hold the actual button objects:
local buttons = {}
As noted by

Code:
-- Now your "buttons" table looks like this:
-- buttons = {
-- 	[1] = <button object named "MyButton1">,
-- 	[2] = <button object named "MyButton2">,
-- }
Now to

Code:
local buttons = {
 	[1] = MyButton1,
 	[2] = MyButton2,
Im not sure if it's the Loop
Code:
for i = 1, #buttonData do
or if I'm supposed to do something I have missed. But more then likely I have done something wrong.
  Reply With Quote
07-09-13, 03:00 AM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
No, there was a mistake in my code (I hadn't tested it in-game when I posted it) and the buttons weren't actually getting stored in the table, so anchoring Button2 failed, causing it to be invisible. I fixed it, so if you copy the code again it should work.

The part at the end is not real code, though, so it should remain commented out; it's just to show you what ends up in the table, so you can do stuff with it later. For example, if later you decided you wanted all the buttons to be 800px wide instead of 200px wide:

Code:
for i = 1, #buttons do
   buttons[i]:SetWidth(800)
end
On a side note, you will likely see the above type of loop written using ipairs in many places:

Code:
for i, button in ipairs(buttons) do
   button:SetWidth(800)
end
While this may seem like a more straightforward way to traverse an indexed table, it's actually a lot slower, and offers no advantages whatsoever over the ipairs-free version, so you should not use it.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
07-09-13, 04:53 AM   #13
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Thanks for all your help.

Im making Progress, been able to add more button and create them into columns. Also able to display tabels from another .lua in the same scrollframe which is the aim of what I wanted to get done when I first make this thread. In my research I found this site http://www.wowwiki.com/API_CreateFrame it mentions un parenting frames when they are hidden to avoid the maximum framelevel. I have used
Code:
	{
		text = "Button A",
		click = function(self, mouseButton)
			print("You clicked Button A!")
			MyParentFrame:Hide()
			MyParentFrame:SetParent(nil)
			MyParentFrame2:Show()
			MyParentFrame2:SetPoint("TOPLEFT", content, 0, 0)
			
		end,
	},
As mentioned to avoid the max framelevel.

TabelTest.lua
Code:
--parent frame 
local frame = CreateFrame("Frame", "MyFrame", UIParent) 
frame:SetSize(410, 300) 
frame:SetPoint("CENTER") 
local texture = frame:CreateTexture() 
texture:SetAllPoints() 
texture:SetTexture(0,0,0,0) 
frame.background = texture 

--scrollframe 
scrollframe = CreateFrame("ScrollFrame", "scrollframe", frame) 
scrollframe:SetPoint("TOPLEFT", 10, -10) 
scrollframe:SetPoint("BOTTOMRIGHT", -10, 10) 
local texture = scrollframe:CreateTexture() 
texture:SetAllPoints() 
texture:SetTexture(0,0,0,0) 
frame.scrollframe = scrollframe 

--scrollbar 
scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate") 
scrollbar:SetPoint("TOPLEFT", frame, "TOPRIGHT", 4, -16) 
scrollbar:SetPoint("BOTTOMLEFT", frame, "BOTTOMRIGHT", 4, 16) 
scrollbar:SetMinMaxValues(1, 20) --How Far the Bar Goes Down and Moves the Frame
scrollbar:SetValueStep(1) 
scrollbar.scrollStep = 1 
scrollbar:SetValue(0) 
scrollbar:SetWidth(16) 
scrollbar:SetScript("OnValueChanged", 
function (self, value) 
self:GetParent():SetVerticalScroll(value) 
end) 
local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") 
scrollbg:SetAllPoints(scrollbar) 
scrollbg:SetTexture(0, 0, 0, 0.4) 
frame.scrollbar = scrollbar 

--content frame 
local content = CreateFrame("Frame", nil, scrollframe)
content:SetPoint("TOP", scrollframe) 
content:SetSize(500, 300) 
local texture = content:CreateTexture() 
--texture:SetAllPoints() 
--texture:SetTexture("Interface\\GLUES\\MainMenu\\Glues-BlizzardLogo") 
--content.texture = texture 
scrollframe.content = content 

scrollframe:SetScrollChild(content)


-- Table describing the buttons you want to create:
local buttonData = {
	{
		text = "Button A",
		click = function(self, mouseButton)
			print("You clicked Button A!")
			MyParentFrame:Hide()
			MyParentFrame:SetParent(nil)
			MyParentFrame2:Show()
			MyParentFrame2:SetPoint("TOPLEFT", content, 0, 0)
			
		end,
	},
	{
		text = "Button B",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
	{
		text = "Button C",
		click = function(self, mouseButton)
			print("You clicked Button C!")
		end,
	},
	{
		text = "Button D",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
	{
		text = "Button E",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
		{
		text = "Button F",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
	{
		text = "Button G",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
	{
		text = "Button H",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
}

-- Table to hold the actual button objects:
local buttons = {}

-- Create the container frame:
local frame = CreateFrame("Frame", "MyParentFrame")
frame:SetPoint("TOPLEFT", content, 0, 0)
frame:SetSize(200, 20)

-- Give it a background:
local backdrop = frame:CreateTexture(nil, "BACKDROP")
backdrop:SetAllPoints(true)
backdrop:SetTexture(0, 0, 0, 0.5)

-- Loop over the data list:
for i = 1, 4 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "MyButton"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 1 then
		-- ...anchor the button to the container:
		button:SetPoint("TOP", frame, "BOTTOM", 0, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end

-- Loop over the data list:
for i = 5, 8 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "MyButton"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 5 then
		-- ...anchor the button to the container:
		button:SetPoint("TOPLEFT", frame, "BOTTOM", 100, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end


-- Now your "buttons" table looks like this:
-- buttons = {
-- 	[1] = <button object named "MyButton1">,
-- 	[2] = <button object named "MyButton2">,
-- }
TabelTest2.lua
Code:
-- Table describing the buttons you want to create:
local buttonData = {
	{
		text = "Button AA",
		click = function(self, mouseButton)
			print("You clicked Button AA!")
			MyParentFrame2:Hide();
			MyParentFrame2:SetParent(nil)
			MyParentFrame:Show();

		end,
	},
	{
		text = "Button BB",
		click = function(self, mouseButton)
			print("You clicked Button BB!")
		end,
	},
	{
		text = "Button CC",
		click = function(self, mouseButton)
			print("You clicked Button CC!")
		end,
	},
	{
		text = "Button DD",
		click = function(self, mouseButton)
			print("You clicked Button DD!")
		end,
	},
	{
		text = "Button EE",
		click = function(self, mouseButton)
			print("You clicked Button EE!")
		end,
	},
		{
		text = "Button FF",
		click = function(self, mouseButton)
			print("You clicked Button FF!")
		end,
	},
	{
		text = "Button GG",
		click = function(self, mouseButton)
			print("You clicked Button GG!")
		end,
	},
	{
		text = "Button HH",
		click = function(self, mouseButton)
			print("You clicked Button HH!")
		end,
	},
}

-- Table to hold the actual button objects:
local buttons = {}

-- Create the container frame:
local frame = CreateFrame("Frame", "MyParentFrame2", UIParent)
frame:Hide()
frame:SetPoint("TOP", UIParent, 0, -300)
frame:SetSize(200, 20)

-- Give it a background:
local backdrop = frame:CreateTexture(nil, "BACKDROP")
backdrop:SetAllPoints(true)
backdrop:SetTexture(0, 0, 0, 0)

-- Loop over the data list:
for i = 1, 4 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "MyButton"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 1 then
		-- ...anchor the button to the container:
		button:SetPoint("TOP", frame, "BOTTOM", 0, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end

-- Loop over the data list:
for i = 5, 8 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "MyButton"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 5 then
		-- ...anchor the button to the container:
		button:SetPoint("TOPLEFT", frame, "BOTTOM", 100, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end


-- Now your "buttons" table looks like this:
-- buttons = {
-- 	[1] = <button object named "MyButton1">,
-- 	[2] = <button object named "MyButton2">,
-- }

function MyButton1_OnClick()
print("test")
end
  Reply With Quote
07-15-13, 07:04 PM   #14
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Im getting a bug that I cant work out. When I first open the addon the scroll frames appear to be working fine, however on subsequent openings there is a bug with the scroll frames. Can someone help me with this.

I have uploaded the full addon to http://www.curseforge.com/media/file.../MapandNav.zip



Main.lua
Code:
-- -- -- -- -- MapandNavStartMenu -- -- -- -- --
local frame = CreateFrame("Frame","MapandNavStartMenu" ,UIParent)
frame:SetWidth(500) -- Set these to whatever height/width is needed 
frame:SetHeight(300) -- for your Texture

local frametexture = frame:CreateTexture(nil,"BACKGROUND")
frametexture:SetTexture("Interface\\AddOns\\MapandNav\\Art\\Background.tga")
frametexture:SetAllPoints(frame)
frame.texture = frametexture
frame:SetPoint("CENTER",0,0)
frame:Hide()
frame:SetScript("OnKeyDown", 
							function(self, Escape, ...)				
							MapandNavStartMenu:Hide()							
							MapandNavFindscrollparentframe:Hide()
							MapandNavscrollframe:Hide()
							MapandNavcontentframe:Hide()
							MapandNavFindtabelperantframe:Hide()
							MapandNavFindtabelperantframe:SetParent(nil)
							MapandNavCitySelecttabelperantframe:Hide()
							MapandNavCitySelecttabelperantframe:SetParent(nil)
							end) 
							
-- -- -- -- -- MapandNavStartButton -- -- -- -- --
local button = CreateFrame("Button", "MapandNavStartButton", UIParent, "UIPanelButtonTemplate")
button:SetText("Start")
button:SetPoint("TOP",0,0)
button:SetWidth(120)
button:SetHeight(50)
button:RegisterForClicks("AnyUp")
button:SetScript("OnClick", 
				function (self, button, down)
				if 
				MapandNavStartMenu:IsVisible() 
				then 
				MapandNavStartMenu:Hide()

				else
				MapandNavStartMenu:Show()
				MapandNavFindButton:Show()
				MapandNavExploreButton:Show()
				end
				end)

-- -- -- -- -- MapandNavStartCloseButton -- -- -- -- --
local button = CreateFrame("button", "MapandNavStartCloseButton", MapandNavStartMenu, "UIPanelCloseButton")
button:SetPoint("TOPRight",-15,-25)
button:SetWidth(40)
button:SetHeight(40)
button:RegisterForClicks("AnyUp")
button:SetScript("OnClick", 
				function (self, button, down)				
							MapandNavStartMenu:Hide()							
							MapandNavFindscrollparentframe:Hide()
							MapandNavscrollframe:Hide()
							MapandNavcontentframe:Hide()
							MapandNavFindtabelperantframe:Hide()
							MapandNavFindtabelperantframe:SetParent(nil)
							MapandNavCitySelecttabelperantframe:Hide()
							MapandNavCitySelecttabelperantframe:SetParent(nil)				
				end)
				
-- -- -- -- -- MapandNavFindButton -- -- -- -- --
local button = CreateFrame("Button", "MapandNavFindButton", MapandNavStartMenu, "UIPanelButtonTemplate")
button:SetText("Find")
button:SetPoint("LEFT", 50,0)
button:SetWidth(180)
button:SetHeight(180)
button:RegisterForClicks("AnyUp")
button:SetScript("OnClick", 
				function (self, button, down)
				MapandNavExploreButton:Hide()
				MapandNavFindButton:Hide()
				MapandNavFindscrollparentframe:Show()
				MapandNavFindtabelperantframe:Show()
				MapandNavscrollframe:Show()
				MapandNavcontentframe:Show()
				
				end)
				
-- -- -- -- -- MapandNavExploreButton -- -- -- -- --
local button = CreateFrame("Button", "MapandNavExploreButton", MapandNavStartMenu, "UIPanelButtonTemplate")
button:SetText("Explore")
button:SetPoint("RIGHT", -50,0)
button:SetWidth(180)
button:SetHeight(180)
button:RegisterForClicks("AnyUp")
button:SetScript("OnClick", 
				function (self, button, down)
				MapandNavExploreButton:Hide()

				MapandNavFindButton:Hide()

				end)
Find.lua
Code:
--parent frame 
local frame = CreateFrame("Frame", "MapandNavFindscrollparentframe", MapandNavStartMenu) 
frame:Hide()
frame:SetSize(400, 200) 
frame:SetPoint("CENTER", MapandNavStartMenu, "CENTER", 0,0) 
local texture = frame:CreateTexture() 
texture:SetAllPoints() 
texture:SetTexture(0,0,0,0) 
frame.background = texture 

--scrollframe 
scrollframe = CreateFrame("ScrollFrame", "MapandNavscrollframe", frame) 
scrollframe:SetPoint("TOPLEFT", 0,0) 
scrollframe:SetPoint("BOTTOMRIGHT", 0,0) 
local texture = scrollframe:CreateTexture() 
texture:SetAllPoints() 
texture:SetTexture(0,0,0,0) 
frame.scrollframe = scrollframe 

--scrollbar 
scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate") 
scrollbar:SetPoint("TOPLEFT", frame, "TOPRIGHT", 6, -22) 
scrollbar:SetPoint("BOTTOMLEFT", frame, "BOTTOMRIGHT", 0,2) 
scrollbar:SetMinMaxValues(1, 200) --How Far the Bar Goes Down and Moves the Frame
scrollbar:SetValueStep(1) 
scrollbar.scrollStep = 1 
scrollbar:SetValue(0) 
scrollbar:SetWidth(16)
 
scrollbar:SetScript("OnValueChanged", 
function (self, value) 
self:GetParent():SetVerticalScroll(value) 
end) 
local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") 
scrollbg:SetAllPoints(scrollbar) 
scrollbg:SetTexture(0, 0, 0, 0.4) 
frame.scrollbar = scrollbar 

--content frame 
local content = CreateFrame("Frame", "MapandNavcontentframe", MapandNavscrollframe) 
content:SetSize(500, 300) 


--local texture = content:CreateTexture() 
--texture:SetAllPoints() 
--texture:SetTexture("Interface\\GLUES\\MainMenu\\Glues-BlizzardLogo") 
--content.texture = texture 

scrollframe.content = content 
 
scrollframe:SetScrollChild(content)

-- Table describing the buttons you want to create:
local buttonData = {
	{
		text = "Auction House",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT1")
			MapandNavFindtabelperantframe:Hide()
			MapandNavFindtabelperantframe:SetParent(nil)
			MapandNavCitySelecttabelperantframe:Show()
			
			
		end,
	},
	{
		text = "Bank",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT2")
		end,
	},
	{
		text = "Barber",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT3")
		end,
	},
	{
		text = "Battle Pet Trainer",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT4")
		end,
	},
	{
		text = "Class Trainer",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT5")
		end,
	},
		{
		text = "Flight Master",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT6")
		end,
	},
	{
		text = "Guild Master",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT7")
		end,
	},
	{
		text = "Guild Vendor",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT8")
		end,
	},
	{
		text = "Inn",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT9")
		end,
	},
	{
		text = "Mailbox",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT1")
		end,
	},
	{
		text = "Points of Interest",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT2")
		end,
	},
	{
		text = "Portals",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT3")
		end,
	},
	{
		text = "Profession Trainer",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT4")
		end,
	},
	{
		text = "Reforge",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT5")
		end,
	},
	{
		text = "Stable Master",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT6")
		end,
	},
	{
		text = "Transmogrification",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT7")
		end,
	},
	{
		text = "Vendor",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT8")
		end,
	},
	{
		text = "Void Storage",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT9")
		end,
	},
}

-- Table to hold the actual button objects:
local buttons = {}

-- Create the container frame:
local frame = CreateFrame("Frame", "MapandNavFindtabelperantframe", MapandNavcontentframe)
frame:Hide()
frame:SetPoint("TOPLEFT", MapandNavcontentframe, 0, 0)
frame:SetSize(200, 20)

-- Give it a background:
local backdrop = frame:CreateTexture(nil, "BACKDROP")
backdrop:SetAllPoints(true)
backdrop:SetTexture(0, 0, 0, 0)

-- Loop over the data list:
for i = 1, 9 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "FindTableOptionsLEFT"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)
	button:SetHeight(40)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 1 then
		-- ...anchor the button to the container:
		button:SetPoint("TOP", frame, "BOTTOM", 0, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end

-- Loop over the data list:
for i = 10, 18 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "FindTableOptionsRIGHT"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)
	button:SetHeight(40)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 10 then
		-- ...anchor the button to the container:
		button:SetPoint("TOPLEFT", frame, "BOTTOM", 100, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end


-- Now your "buttons" table looks like this:
-- buttons = {
-- 	[1] = <button object named "MyButton1">,
-- 	[2] = <button object named "MyButton2">,
-- }

-- Table describing the buttons you want to create:
local buttonData = {
	{
		text = "Dalaran",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT1")
			
		end,
	},
	{
		text = "Darnassus",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT2")
			
		end,
	},
	{
		text = "Exodar",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT3")
			
		end,
	},
	{
		text = "Ironforge",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT4")
			
		end,
	},
	{
		text = "Orgrimmar",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT5")
			
		end,
	},
	{
		text = "Shattrath City",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT6")
			
		end,
	},
	{
		text = "Shrine of Seven Stars",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT1")
			
		end,
	},
	{
		text = "Shrine of Two Moons",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT2")
			
		end,
	},
	{
		text = "Silvermoon City",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT3")
			
		end,
	},
	{
		text = "Stormwind City",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT4")
			
		end,
	},
	{
		text = "Thunder Bluff",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT5")
			
		end,
	},
	{
		text = "Undercity",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT6")
			
		end,
	},
}


-- Table to hold the actual button objects:
local buttons = {}

-- Create the container frame:
local frame = CreateFrame("Frame", "MapandNavCitySelecttabelperantframe", MapandNavcontentframe)
frame:Hide()
frame:SetPoint("TOPLEFT", MapandNavcontentframe, 0, 0)
frame:SetSize(200, 20)

-- Give it a background:
local backdrop = frame:CreateTexture(nil, "BACKDROP")
backdrop:SetAllPoints(true)
backdrop:SetTexture(0, 0, 0, 0)

-- Loop over the data list:
for i = 1, 6 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "FindTableOptionsLEFT"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)
	button:SetHeight(40)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 1 then
		-- ...anchor the button to the container:
		button:SetPoint("TOP", frame, "BOTTOM", 0, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end

-- Loop over the data list:
for i = 7, 12 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "FindTableOptionsRIGHT"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)
	button:SetHeight(40)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 10 then
		-- ...anchor the button to the container:
		button:SetPoint("TOPLEFT", frame, "BOTTOM", 100, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end


-- Now your "buttons" table looks like this:
-- buttons = {
-- 	[1] = <button object named "MyButton1">,
-- 	[2] = <button object named "MyButton2">,
-- }
CitySelect.lua
Code:
-- Table describing the buttons you want to create:
local buttonData = {
	{
		text = "Dalaran",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT1")
			
		end,
	},
	{
		text = "Darnassus",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT2")
			
		end,
	},
	{
		text = "Exodar",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT3")
			
		end,
	},
	{
		text = "Ironforge",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT4")
			
		end,
	},
	{
		text = "Orgrimmar",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT5")
			
		end,
	},
	{
		text = "Shattrath City",
		click = function(self, mouseButton)
			print("FindTableOptionsLEFT6")
			
		end,
	},
	{
		text = "Shrine of Seven Stars",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT1")
			
		end,
	},
	{
		text = "Shrine of Two Moons",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT2")
			
		end,
	},
	{
		text = "Silvermoon City",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT3")
			
		end,
	},
	{
		text = "Stormwind City",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT4")
			
		end,
	},
	{
		text = "Thunder Bluff",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT5")
			
		end,
	},
	{
		text = "Undercity",
		click = function(self, mouseButton)
			print("FindTableOptionsRIGHT6")
			
		end,
	},
}


-- Table to hold the actual button objects:
local buttons = {}

-- Create the container frame:
local frame = CreateFrame("Frame", "MapandNavCitySelecttabelperantframe", MapandNavcontentframe)
frame:Hide()
frame:SetPoint("TOPLEFT", MapandNavcontentframe, 0, 0)
frame:SetSize(200, 20)

-- Give it a background:
local backdrop = frame:CreateTexture(nil, "BACKDROP")
backdrop:SetAllPoints(true)
backdrop:SetTexture(0, 0, 0, 0)

-- Loop over the data list:
for i = 1, 6 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "FindTableOptionsLEFT"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)
	button:SetHeight(40)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 1 then
		-- ...anchor the button to the container:
		button:SetPoint("TOP", frame, "BOTTOM", 0, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end

-- Loop over the data list:
for i = 7, 12 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "FindTableOptionsRIGHT"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)
	button:SetHeight(40)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 10 then
		-- ...anchor the button to the container:
		button:SetPoint("TOPLEFT", frame, "BOTTOM", 100, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end


-- Now your "buttons" table looks like this:
-- buttons = {
-- 	[1] = <button object named "MyButton1">,
-- 	[2] = <button object named "MyButton2">,
-- }

Last edited by Yksrep : 07-16-13 at 03:43 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » New author requiring some help

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