Thread Tools Display Modes
04-17-14, 04:33 PM   #1
deapee
A Defias Bandit
Join Date: Apr 2014
Posts: 2
what is needed to create this addon...

First, excuse me as I'm writing on my phone so I'll have to be brief.

That said, I want to create a window (I have managed to do this with create frame).

This window I created is moveable...

I want to be able to add text to it, or more specifically lines of text that will cause the window to grow or shrink as needed.

--

I can't even get text to show up on my frame. I was able to get a button centered on it.

--

Also, can this functionality be done solely in lua, or should I be looking at XML as well?

Thanks

Last edited by deapee : 04-17-14 at 05:30 PM.
  Reply With Quote
04-17-14, 06:44 PM   #2
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
Making frames draggable
- http://www.wowpedia.com/Making_draggable_frames

Creating text/Setting fonts
- http://www.wowwiki.com/API_Frame_CreateFontString
- http://www.wowpedia.org/API_FontInstance_SetFont
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
04-17-14, 07:39 PM   #3
deapee
A Defias Bandit
Join Date: Apr 2014
Posts: 2
Thanks.

So you think that the best way to add an ever-changing amount of text lines to a window would be simply by sending text directly to that frame?

--

I am actually doing ok now, I can set font to the frame. Should I make frames that are the main frame's child and set font to that?

I mean I'd be ok with having like 5 maximum things displayed at any time.

--

IE

this is the MAIN frame
-------------------------
| |
| |
| |
| |
| |
| |
| |
| |
-------------------------

-------------------------
| | CHILD FRAME | |
| |
| | CHILD FRAME | |
| |
| | CHILD FRAME | |
| |
| | CHILD FRAME | |
| |
-------------------------

Or just output text directly to the main frame? I see how to create a new line with \n but How could I add and subtract dynamically changing items to that?

--

I think I'm going to just give up.

--

Of course the forums delete the spaces
  Reply With Quote
04-17-14, 08:13 PM   #4
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Well, what exactly are you trying to do? Would you simply like to show a text with multiple rows (like a tooltip), or would you like to have independent text parts that could be shown, hide, moved, sized, whatever indepentently (like the item list in the action window)?
  Reply With Quote
04-17-14, 08:53 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The only thing you can't do in Lua is create a template, but the only thing you need templates for are certain uncommon cases involving very advanced secure frames (unitframe/actionbutton) usage, so chances are you will never want to do anything that can't be done in Lua.

Here's a simple example of creating a movable frame with a title, a button, and font string, and resizing the frame based on the contents of the font string:

Code:
-- Give your main object a global name so you can access it more easily for debugging:
local frame = CreateFrame("Frame", "MyTestFrame", UIParent)

-- Put the frame in the middle of the screen:
frame:SetPoint("BOTTOM", UIParent, "CENTER", 0, 100)

-- Give it a starting size:
frame:SetSize(500, 200)

-- Give it a backdrop so you can see it:
frame:SetBackdrop({
     bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, tileSize = 16,
     edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 5,
     insets = { left = 5, right = 5, top = 5, bottom = 5 },
})
frame:SetBackdropColor(0, 0, 0)
frame:SetBackdropBorderColor(1, 1, 1)

-- Add a title:
local title = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("TOP", 0, -2)
title:SetText("My Test Frame")
-- Make it easy to access:
frame.Title = title

-- Make it draggable by the title:
local titleRegion = frame:CreateTitleRegion()
titleRegion:SetPoint("BOTTOMLEFT", title, -5, -2)
titleRegion:SetPoint("TOPRIGHT", title, 5, 2)
frame.TitleRegion = titleRegion

-- Add a button at the bottom. Use the pre-defined template for the "red button" style:
local button = CreateFrame("Button", "$parentOkayButton", frame, "UIPanelButtonTemplate")
button:SetPoint("BOTTOM", 0, 16)
button:SetText(OKAY) -- Use a pre-defined global string so it's "correct" in all WoW languages.
-- Make it close the frame when clicked:
button:SetScript("OnClick", function(self) self:GetParent():Hide() end)
frame.OkayButton = button

-- Add a font string in the middle:
local text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
text:SetPoint("LEFT", 16, 0)
text:SetPoint("RIGHT", -16, 0)
text:SetPoint("TOP", title, "BOTTOM", 0, -16)
text:SetPoint("BOTTOM", button, "TOP", 0, 16)
text:SetJustifyH("CENTER")
text:SetJustifyV("TOP")
frame.Text = text

-- Frames don't normally have a SetText method, but we'll add one that sets the
-- text of the frame's font string, and adjusts the size of the frame to match.
function frame:SetText(text)
     -- Set the text of the font string:
     self.Text:SetText(text)
     -- Find out how long the text is:
     local width = self.Text:GetStringWidth()
    -- Make sure it's at least as wide as the title and button:
    local titleWidth = self.Title:GetWidth()
    local buttonWidth = self.Button:GetWidth()
    width = math.max(width, titleWidth, buttonWidth)
     -- And adjust the width of the frame, accounting for the inner padding:
     self:SetWidth(width + 32)
end

-- Then use it like this:
frame:SetText("This is my test frame! It has some text in it!")

-- Try a longer font string:
frame:SetText("Here is a long string. It doesn't really say anything. It's just long, so you can see how the frame gets bigger.")

-- And a shorter one:
frame:SetText("It's so short!")
For a more complete example of a frame with multiple rows of text, that shows a maximum of X lines at once and scrolls to show the rest, see here:

http://forums.wowace.com/showthread.php?p=320619
__________________
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

WoWInterface » Developer Discussions » Lua/XML Help » what is needed to create this addon...


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