Originally Posted by Yksrep
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
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