Thread Tools Display Modes
06-13-09, 04:45 PM   #1
CalciumIRL
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 15
Simple Single Frame AddOn

So I'm kind of new to Lua scripting and all I need is this ridiculously simple AddOn.

I need 1 frame implemented into my UI, but I don't want to get kgPanels to put it in, since it's just a single frame, but I want it there all the time. I have the texture but all I need to do is enable the frame but it won't work.

Just for the purposes of this, the texture is located at "Interface\\AddOns\\Textures\\Frame.tga".

What Lua code would I need so that when I go into WoW, this texture is just there in the middle of my screen as a background image. I would be able to adjust the xpos and ypos myself but I just need to know how to put it into the game.

Thanks for your time!
  Reply With Quote
06-13-09, 04:50 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,919
It might be worth the time to look at wow wikis pages on lua and xml scripting for wow. It helped me get my toes into the water and then I found an addon that did something similar to what I wanted and looked at what they did and went from there.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
06-13-09, 05:01 PM   #3
CalciumIRL
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 15
The annoying thing is that that sends me to external links or doesn't help me at all, I mean, I already know drips and drabs of Lua but it's just flying by my head why this isn't working. If I were to have someone code the script for me (And I presume it's just a few lines or I'm doing something wrong) I would be able to see why my initial ones have failed and what it does.
  Reply With Quote
06-13-09, 05:07 PM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,919
Hmm strange Ive never had that happen to me .. but let me see .. do you use xml with lua or just pure lua ?

Here's what I do in pure lua code. It is pretty basic but putting this into the lua file it should create a small window with a slightly transparent background. Hopefully that will help you.

Code:
local MyFrame;

function OnMouseDown(frame)
        if (( ( not frame.isLocked ) or ( frame.isLocked == 0 ) )) then
                frame:StartMoving();
                frame.isMoving = true;
        end
end

function OnMouseUp(frame)
        if ( frame.isMoving ) then
                frame:StopMovingOrSizing();
                frame.isMoving = false;
        end
end

function OnHide(frame)
        if ( frame.isMoving ) then
                frame:StopMovingOrSizing();
                frame.isMoving = false;
        end
end

function CreateMyFrame()
    -- Create the Frame
    MyFrame = CreateFrame("Frame","MyFrame",UIParent);
    -- Make Frame Movable and attach functionality
    MyFrame:RegisterForDrag("LEFTBUTTON");
    MyFrame:EnableMouse(true);
    MyFrame:SetMovable(true);
    MyFrame:SetScript("OnMouseDown",OnMouseDown);
    MyFrame:SetScript("OnMouseUp",OnMouseUp);
    MyFrame:SetScript("OnHide",OnHide);
    -- Set Strata Level and Size
    MyFrame:SetFrameStrata("BACKGROUND");
    MyFrame:SetWidth(300); -- Set these to whatever height/width is needed 
    MyFrame:SetHeight(200); -- for your Texture  
    -- Clamp to screen and center it with no opacity        
    MyFrame:SetClampedToScreen(true);
    MyFrame:SetPoint("CENTER",0,0);
    MyFrame:SetAlpha(1.0);
    -- Set the Backdrop
    MyFrame:SetBackdrop( 
    { 
         bgFile = "Interface/Tooltips/UI-Tooltip-Background", 
         edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 
         tile = true, 
         tileSize = 16, 
         edgeSize = 16, 
         insets = { left = 4, right = 4, top = 4, bottom = 4 }
     }
     );
     MyFrame:SetBackdropColor(0,0,0,1);
     MyFrame:SetBackdropBorderColor(255,255,0,1);
    
end


CreateMyFrame();
MyFrame:Hide() -- To Hide the Frame
Or
MyFrame:Show() -- To Show the Frame
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 06-13-09 at 05:20 PM.
  Reply With Quote
06-13-09, 05:09 PM   #5
CalciumIRL
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 15
Currently it's pure Lua, and I'd prefer that if you can.

If you have an IRC client would it be easier to talk through that?

1. Well actually, all I need it to do is put a texture into WoW as a base. I just need it hung to the top of my screen as a backdrop for my SLDT Elements. Currently I have...

Code:
local a = CreateFrame("Frame", nil, UIParent)
a:SetFrameStrata("BACKGROUND")
a:SetTexture("Interface\\AddOns\\rTextures\\SLDT_Frame.tga")
a:SetWidth(1280)
a:SetHeight(200)
a:SetPoint("CENTER", 0, 0)
a:Show()

Last edited by CalciumIRL : 06-13-09 at 05:26 PM.
  Reply With Quote
06-13-09, 05:22 PM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,919
Ah, thats cool I prefer pure lua myself.

Feel free to take a look at any of my addons. TotemDeathWatcher is the most basic one for displaying information with LootAlerter the more informative one.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
06-13-09, 05:36 PM   #7
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Frames don't have a SetTexture method. You need to

Code:
a:SetFrameStrata("BACKGROUND")
a:SetWidth(1280)
a:SetHeight(200)
a:SetPoint("CENTER", 0, 0)
local t = a:CreateTexture()
t:SetAllPoints()
t:SetTexture("Interface\\AddOns\\rTextures\\SLDT_Frame.tga")
see...
http://www.wowwiki.com/API_Frame_CreateTexture
  Reply With Quote
06-13-09, 05:48 PM   #8
CalciumIRL
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 15
Ok so now I have:

Code:
local a = CreateFrame("Frame", nil, UIParent)
a:SetFrameStrata("BACKGROUND")
a:SetWidth(1280)
a:SetHeight(200)
a:SetPoint("CENTER", 0, 0)
local t = a:CreateTexture()
t:SetAllPoints()
t:SetTexture("Interface\\AddOns\\rTextures\\SLDT_Frame.tga")
But it's still not working. I have checked the texture and path and they are both fine. What else could be the issue?
  Reply With Quote
06-13-09, 05:54 PM   #9
Recluse
A Cliff Giant
 
Recluse's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 70
Code:
local t = a:CreateTexture()
I think you need to specify the layer to draw the texture on? And a nil for the first argument, since it does not need a name.
Code:
t:SetAllPoints()
I'm fairly sure, that even though it has a parent object, you still have to pass in the relative frame as an argument?

And don't forget to use :Show() on your frame at the end.
Code:
local a = CreateFrame("Frame", nil, UIParent)
a:SetFrameStrata("BACKGROUND")
a:SetWidth(1280)
a:SetHeight(200)
a:SetPoint("CENTER", 0, 0)
local t = a:CreateTexture(nil, "BACKGROUND")
t:SetAllPoints(a)
t:SetTexture("Interface\\AddOns\\rTextures\\SLDT_Frame.tga")
a:Show()
__________________
We'd be together, but only diamonds last forever...
  Reply With Quote
06-13-09, 06:04 PM   #10
CalciumIRL
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 15
That doesn't work either.

Would there be a way to, instead of putting in the texture, just make a block of colour to test it?
  Reply With Quote
06-13-09, 06:11 PM   #11
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
Originally Posted by recluse View Post
I'm fairly sure, that even though it has a parent object, you still have to pass in the relative frame as an argument?
The relative frame doesn't need to be passed to SetAllPoints if you want it to be relative to the parent.

Originally Posted by CalciumIRL View Post
That doesn't work either.

Would there be a way to, instead of putting in the texture, just make a block of colour to test it?
t:SetTexture(0, 0, 0) -- SetTexture accepts RGB (and optional alpha) values.
  Reply With Quote
06-13-09, 06:19 PM   #12
Recluse
A Cliff Giant
 
Recluse's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 70
Showing a black square in center of screen:

TestFrame.toc
Code:
## Interface: 30100
## Title: TestFrame
## Author: Recluse

TestFrame.lua
TestFrame.lua
Code:
local f = CreateFrame("Frame", "TestFrame", UIParent)
f:SetFrameStrata("BACKGROUND")
f:SetWidth(100)
f:SetHeight(100)
f:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
f.texture = f:CreateTexture(nil, "BACKGROUND")
f.texture:SetAllPoints(f)
f.texture:SetTexture(0, 0, 0, 1)
You can just set the texture to an rgba value like this instead of a file.

Also, you said you wanted to pin your texture to the top of the screen, so you'll want to change it to f:SetPoint("TOP", UIParent, "TOP", 0, 0) I think. (yeah, I use the long version of SetPoint =x)

If this works, then make sure your image follows the correct rules maybe?
http://www.wowwiki.com/API_Texture_SetTexture

Originally Posted by Waverian View Post
The relative frame doesn't need to be passed to SetAllPoints if you want it to be relative to the parent.
Interesting, I had no idea
__________________
We'd be together, but only diamonds last forever...

Last edited by Recluse : 06-13-09 at 06:22 PM.
  Reply With Quote
06-13-09, 06:19 PM   #13
CalciumIRL
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 15
Well the thing Waverian said works. So there must be something wrong with my texture! Awesome. Now to figure this one out...

I have the texture in saved as a .tga file. And when I open it my texture is there with a black background. But apparently the texture doesn't show in game so what would be wrong?

EDIT: So I've looked at a similar, shorter version of the texture and I notice there is an outline around the actual texture, where as on the one I created, there is no such line. I guess this indicates to the game the part that needs to be put in the game.

Last edited by CalciumIRL : 06-13-09 at 06:24 PM.
  Reply With Quote
06-13-09, 06:34 PM   #14
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Waverian View Post
The relative frame doesn't need to be passed to SetAllPoints if you want it to be relative to the parent.
I'm also pretty sure that you don't need to explicitly give a texture a layer.
  Reply With Quote
06-13-09, 06:35 PM   #15
CalciumIRL
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 15
Originally Posted by CalciumIRL View Post
Well the thing Waverian said works. So there must be something wrong with my texture! Awesome. Now to figure this one out...

I have the texture in saved as a .tga file. And when I open it my texture is there with a black background. But apparently the texture doesn't show in game so what would be wrong?

EDIT: So I've looked at a similar, shorter version of the texture and I notice there is an outline around the actual texture, where as on the one I created, there is no such line. I guess this indicates to the game the part that needs to be put in the game.
Ok, I had no selection when choosing my texture, hence why nothing showed up - no part of it was selected! But now I'm having a bit of trouble selecting the part I want but I'll see what I can do

EDIT: My texture just doesn't want to work, even with a selection added. |;

Last edited by CalciumIRL : 06-13-09 at 06:46 PM.
  Reply With Quote
06-13-09, 07:40 PM   #16
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by CalciumIRL View Post
Ok, I had no selection when choosing my texture, hence why nothing showed up - no part of it was selected! But now I'm having a bit of trouble selecting the part I want but I'll see what I can do

EDIT: My texture just doesn't want to work, even with a selection added. |;
When you say "selection" do you mean using texture:SetTexCoord?

Also, if you didn't already know, textures need to have a resolution that is powers of 2 (i.e. 256x128, etc...) -- I think they also have to be 24 bit color + alpha channel.
  Reply With Quote
06-13-09, 08:53 PM   #17
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Why bother with creating a second frame for the texture? All you need to do is set your image as the backdrop to the original frame. What you had originally, CalciumIRL, is correct, except you need to use this function instead of SetTexture. (You also don't need to call Show(), as a frame is implicitly shown upon creation.)

Code:
local a = CreateFrame("Frame", nil, UIParent)
a:SetFrameStrata("BACKGROUND")
a:SetBackdrop({bgFile = "Interface\\AddOns\\rTextures\\SLDT_Frame.tga"})
a:SetWidth(1280)
a:SetHeight(200)
a:SetPoint("CENTER", 0, 0)
__________________
"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
06-13-09, 09:28 PM   #18
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Seerah View Post
Why bother with creating a second frame for the texture?
Can you do the equivalent of SetTexCoord on a frame backdrop? Otherwise, aren't you limited to frames with 2^n pixel dimensions unless you want it to be distorted (i.e. not 1280x200)?
  Reply With Quote
06-14-09, 05:18 AM   #19
CalciumIRL
A Deviate Faerie Dragon
AddOn Compiler - Click to view compilations
Join Date: Oct 2008
Posts: 15
Well I couldn't get my texture to work but I used another one and just stacked it using :SetFrameLevel() and it actually turned out better than my initial idea for it
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Simple Single Frame AddOn

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