Thread Tools Display Modes
12-19-14, 10:55 PM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Exclamation Help with making frames

Hello,

I've spent countless hours trying to find half decent material on how to create a dialog-like window/frame within WoW. I've looked through wowwiki and numerous others site that are very vague. I'm simply trying to make a square window that shows some text. Any assistance with this would be greatly appreciated!
  Reply With Quote
12-19-14, 11:20 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Lua Code:
  1. --create your frame
  2. --(note, you don't have to give your frame a global name, you can pass nil as the second argument instead)
  3. local frame = CreateFrame("Frame", "MyFrameName", UIParent)
  4.  
  5. --give your frame a size
  6. frame:SetSize(150, 150)
  7.  
  8. --give your frame something to look like
  9. frame:SetBackdrop({bgFile = "Path\\to\\texture"})
  10.  
  11. --give your frame a location on screen
  12. frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  13.  
  14. --now make a fontstring for your text
  15. --(again, a global name is optional)
  16. local text = frame:CreateFontString("MyFrameText")
  17.  
  18. --give your text something to look like
  19. text:SetFont("Path\\to\\font", 12, "NORMAL")
  20.  
  21. --give your text some actual text
  22. text:SetText("This is my message to display.")

http://wowprogramming.com/docs/api/CreateFrame
http://wowprogramming.com/docs/widgets/Region/SetSize
http://wowprogramming.com/docs/widge...me/SetBackdrop
http://wowprogramming.com/docs/widgets/Region/SetPoint
http://wowprogramming.com/docs/widge...eateFontString
http://wowprogramming.com/docs/widge...stance/SetFont
http://wowprogramming.com/docs/widge...String/SetText

Also note that both CreateFrame and CreateFontString may use a template to define looks, font used, etc.
__________________
"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
12-19-14, 11:22 PM   #3
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
You sir, are my hero! Thank you very much, this is exactly what I'm looking for!
  Reply With Quote
12-20-14, 11:22 AM   #4
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Originally Posted by Sweetsour View Post
You sir, are my hero! Thank you very much, this is exactly what I'm looking for!
That should be Ma'am or Miss. I know it is hard to tell with the internet sometimes.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-31-14, 04:48 PM   #5
Dandamis
A Kobold Labourer
Join Date: Dec 2014
Posts: 1
I know the feeling of not being able to find out how to create some of the most basic elements. You got a perfect example! From this Frame you can build quite interesting applications already. Think Handlers (OnEvent, OnClick, OnUpdate) and Events (PLAYER_XP_UPDATE, ADDON_LOADED, etc) and you'll be going in no-time.

What I found helpful in my one day experience of making Addons:

Code:
local last = 0;
frame:SetScript("OnUpdate", function(self, elapsed)
	last = last + elapsed;
	
	if last >= 1 then
		-- Your code
		last = 0;
	end
end)
So the structure of your lua could look something like this:
Code:
-- VARIABLES
-- FRAME CREATION
-- STRING CREATION
-- EVENT REGISTRATION
-- ONEVENT FUNCTIONS
-- ONUPDATE FUNCTIONS
-- SUPPORT FUNCTIONS
This will allow you to create exciting stuff without the need of any XML.
__________________
  Reply With Quote
12-31-14, 05:20 PM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Also, if you want to change the fontstring to an already established wow font you can use the following instead:

text:SetFontObject("GameFontNormalHuge")

This automatically uses a font style from the font file ( "Fonts\FRIZQT__.TTF" ) and size ( "20" ) with no outline but a yellowish color instead of white.

http://wow.gamepedia.com/API_FontInstance_SetFontObject
__________________
  Reply With Quote
12-31-14, 07:12 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Dandamis View Post
What I found helpful in my one day experience of making Addons:
Code:
local last = 0;
frame:SetScript("OnUpdate", function(self, elapsed)
	last = last + elapsed;
	
	if last >= 1 then
		-- Your code
		last = 0;
	end
end)
OnUpdate polling is generally the worst (ie. most computationally expensive) way to accomplish anything. If there's an event that fires to tell you when your code should do something, you should always use an event handler instead instead. And since 6.0 there is now an actual timer API built into the game, so if you need to repeat something every 1 second as in your example code, you should do this instead:

Code:
local function Update()
     -- your code

    -- Tell it to repeat again in 1 second:
    C_Timer.After(1, Update)
end

-- Start it:
Update()
(There's also C_Timer.NewTimer and C_Timer.NewTicker methods that automate the repeating for you, but they're implemented in Lua, not in C, and are rather inefficient in typical Blizzard fashion, so it's better to just handle it yourself.)
__________________
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
01-01-15, 03:44 AM   #8
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by Phanx View Post
(There's also C_Timer.NewTimer and C_Timer.NewTicker methods that automate the repeating for you, but they're implemented in Lua, not in C, and are rather inefficient in typical Blizzard fashion, so it's better to just handle it yourself.)
They're not.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
01-01-15, 10:36 AM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Torhal View Post
They're not.
They're not what? Implemented in Lua? Yes they are. Inefficient? Creating new tables (with metatables, even) and new functions for every repeating timer seems pretty inefficient to me, when it's trivial to do "repeat X times and stop" or "cancel this repeating timer" yourself without that overhead.

Code:
local n = 5
local function Update()
     -- stuff
     n = n - 1
     if n > 0 then C_Timer.After(5, Update) end
end
C_Timer.After(5, Update)
Code:
local stop
local function Update()
     if stop then return end
     -- stuff
     C_Timer.After(5, Update)
end
C_Timer.After(5, Update)
-- then in some event handler or wherever:
stop = true
If you're writing an arena macro, sure, go ahead and use them to save space. If you're writing an addon, I just don't see any compelling argument in favor of using them.
__________________
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 » Help with making frames

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