WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Simple Single Frame AddOn (https://www.wowinterface.com/forums/showthread.php?t=24740)

CalciumIRL 06-13-09 04:45 PM

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!

Xrystal 06-13-09 04:50 PM

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.

CalciumIRL 06-13-09 05:01 PM

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.

Xrystal 06-13-09 05:07 PM

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


CalciumIRL 06-13-09 05:09 PM

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()


Xrystal 06-13-09 05:22 PM

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.

Akryn 06-13-09 05:36 PM

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

CalciumIRL 06-13-09 05:48 PM

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?

Recluse 06-13-09 05:54 PM

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()


CalciumIRL 06-13-09 06:04 PM

That doesn't work either. :p

Would there be a way to, instead of putting in the texture, just make a block of colour to test it?

Waverian 06-13-09 06:11 PM

Quote:

Originally Posted by recluse (Post 142951)
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.

Quote:

Originally Posted by CalciumIRL (Post 142954)
That doesn't work either. :p

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.

Recluse 06-13-09 06:19 PM

:) 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

Quote:

Originally Posted by Waverian (Post 142955)
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 :)

CalciumIRL 06-13-09 06:19 PM

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.

Akryn 06-13-09 06:34 PM

Quote:

Originally Posted by Waverian (Post 142955)
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.

CalciumIRL 06-13-09 06:35 PM

Quote:

Originally Posted by CalciumIRL (Post 142957)
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. |;

Akryn 06-13-09 07:40 PM

Quote:

Originally Posted by CalciumIRL (Post 142961)
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.

Seerah 06-13-09 08:53 PM

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)


Akryn 06-13-09 09:28 PM

Quote:

Originally Posted by Seerah (Post 142972)
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)?

CalciumIRL 06-14-09 05:18 AM

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 :)


All times are GMT -6. The time now is 08:33 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI