Thread Tools Display Modes
03-06-11, 09:10 AM   #1
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Few Question's regarding creating frames.

Hello,

i have been working on a small addon to make UI panels. Instead of using kgpanels and other simular addons.
Mostly to learn how to write addon's myself.

So here is some question's i have:

Default code im using on frames:
Code:
function CreateLBottom() --Left Bottombar/Infotab

    LBottom = CreateFrame("Frame","LBottom",UIParent);
    LBottom:SetFrameStrata("BACKGROUND");
    LBottom:SetWidth(CPwidth); 
    LBottom:SetHeight(CPbarsheight); 
    LBottom:SetClampedToScreen(true);
	LBottom:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 2, 2)
    LBottom:SetAlpha(1.0);
    LBottom:SetBackdrop(BACKD);
     LBottom:SetBackdropColor(Backdropcolors);
     LBottom:SetBackdropBorderColor(1,1,1,1);
    
end
Im using the following default values:
Code:
local BACKD =     { 
         bgFile = "Interface\\FrameGeneral\\UI-Background-Marble", 
         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", 
         tile = false, 
         tileSize = 16, 
         edgeSize = edgeS, 
         insets = inseT
     }
local CPwidth = 300
local CPbarsheight = 20
local edgeS = 8
local inseT = { left = 0, right = 0, top = 0, bottom = 0 }
Question 1: Can i make a new frame by using the above frame as template and just change the hight of the next frame? How?

Question 2: How can i make a frame to only show if a addon is loaded? And i don't mean just parent the frame to that addon.

Question 3: How can i make a slash comman to toggle 1 of the panels?

Trouble 1: When i try to add a default value for border color it doesn't use the right color. Most of the time the border becomes red.
Here is how im trying todo it.
Code:
local BColor_r = 0.5,0.5,0.5,1

LBottom:SetBackdropBorderColor(BColor_r);
And i can't seem to get this to work:
Code:
local BColor_r = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b
Question 4: Is there any command/math formula to calculate how big the edgsize should be? Cause it seem's to be a conection between width and hight of panels. If i just use same edgsize on small frames and big frames the border becomes blury.
I have my UI scale set by: /run SetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))

Last Question: How can i make a panel width to be 99% of the screen? To use as a top panel.

Many questions i know Im just starting to learn this LUA stuff.

Thx in advance for replys.

Last edited by frohanss : 03-06-11 at 09:18 AM.
  Reply With Quote
03-06-11, 10:34 AM   #2
Sniffles
A Black Drake
 
Sniffles's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 86
Question 1: Can i make a new frame by using the above frame as template and just change the hight of the next frame? How?

Question 2: How can i make a frame to only show if a addon is loaded? And i don't mean just parent the frame to that addon.

Question 3: How can i make a slash comman to toggle 1 of the panels?

Trouble 1: When i try to add a default value for border color it doesn't use the right color. Most of the time the border becomes red.
Here is how im trying todo it.

Question 4: Is there any command/math formula to calculate how big the edgsize should be? Cause it seem's to be a conection between width and hight of panels. If i just use same edgsize on small frames and big frames the border becomes blury.
I have my UI scale set by: /run SetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))

Last Question: How can i make a panel width to be 99% of the screen? To use as a top panel.

You can do a function like these:

Code:
function CreateHolder(f, w, h, anchor, parent, anchor, x, y)
f:SetWidth(w)
f:SetHeight(h)
f:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8x8", edgeFile = "Interface\\Buttons\\WHITE8x8", edgeSize = 1, })
f:SetBackdropColor(0, 0, 0, 0)
f:SetBackdropBorderColor(0, 0, 0, 0)
f:SetPoint(anchor, parent, anchor, x, y)
end
Then you can do for each frame:

local Frame = CreateFrame("Frame", "FrameName", UIParent)
CreateHolder(Frame, WIDTH, HEIGHT, "CENTER", UIParent, "CENTER", 0, 0)

2.
Code:
if IsAddOnLoaded("MyAddon") and MyFrameName:IsVisible() then
 MyFrame:Show()
end
3.

Code:
local f = CreateFrame(...)
..
..
f:Hide()
Code:
local show = false
SlashCmdList['showpanel'] = function()
if show == false then
show = true
f:Show()
elseif show == true then
show = false
f:Hide()
end
end
SLASH_showpanel1 = '/show'
4.
Code:
local r, g, b = RAID_CLASS_COLORS[select(2, UnitClass("player"))]

Frame:SetBackdropColor(r, g, b)
Frame:SetBackdropBorderColor(r, g, b)
Last Question.
width(WorldFrame:GetWidth()-20)

For bordersizes do
edgeSize = 1
insets = -1
  Reply With Quote
03-06-11, 11:20 AM   #3
lilsparky
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 117
that's a lot of questions. i'll just mention a few things.

use locals when you can. local variables are limited to the current scope (meaning they are only defined inside of the current do..end block -- each .lua file can be thought of as having a do..end around its entirety). also, they are defined top down. so in order to reference a local properly, you must declare it first, otherwise you're referencing a global of the same name (which is likely a mistake and will probably result in a reference to a nil). you've got a few cases where you're defining a variable as local AFTER it's been referenced in another table (your edge and inset values).

the comma syntax you're using in your color assignment is wrong. commas in lua assignments will match up from the right hand side to the left hand side. so you should do: "local r,g,b,a = 1,.5,.5,1" and then use r,g,b,a in the set backdrop color. or of course, just use those fixed values in the function call.
  Reply With Quote
03-06-11, 11:57 AM   #4
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Thx so much both of you for the replys. And big thx Sniffles for the extended reply.

Gona start digging into this and see if i can improve my "addon"
  Reply With Quote
03-08-11, 08:33 AM   #5
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Can't seem to get the panels to hide if addon isn't loaded or toggle it on/off with slash command.

Can i kind person help me out some?

Code:
function CreateHolder(f, w, h, anchor, parent, anchor, x, y)
f:SetWidth(w)
f:SetHeight(h)
f:SetFrameStrata("BACKGROUND")
f:SetBackdrop({ bgFile = "Interface\\FrameGeneral\\UI-Background-Marble", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 8, })
f:SetBackdropColor(Backdropcolors)
f:SetBackdropBorderColor(1,1,1,1)
f:SetPoint(anchor, parent, anchor, x, y)
end

local Frame = CreateFrame("Frame", "Addon", UIParent)
CreateHolder(Frame, 217, 26, "TOPRIGHT", UIParent, "TOPRIGHT", -2, -2)

local Frame = CreateFrame("Frame", "Toggle", UIParent)
CreateHolder(Frame, 26, 26, "TOPLEFT", UIParent, "TOPLEFT", -27, 0)
It's just a example panels. How should i make it so that "addon" panel is only visible if Recount is loaded? And How to add slash command to "Toggle" panel?

Have tryed different settings and can't figure it out
  Reply With Quote
03-08-11, 09:29 AM   #6
Coote
A Scalebane Royal Guard
 
Coote's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 440
Originally Posted by frohanss View Post
It's just a example panels. How should i make it so that "addon" panel is only visible if Recount is loaded?
Change UIParent to the name of Recount's frame name.

Example...

Code:
local Frame = CreateFrame("Frame", "Addon", recount)
CreateHolder(Frame, 217, 26, "TOPRIGHT", recount, "TOPRIGHT", -2, -2)
I'm fairly sure I've got the frame name for it wrong, but I'm unable to check for myself. When you're in-game, use /framestack and hover your mouse over Recount to get the actual frame name.
__________________

"This is the fifteen-thousandth four hundredth and ninety-eighth occurence".
  Reply With Quote
03-08-11, 09:57 AM   #7
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Thx for the reply.
Maybe Recount was bad example to mention since it actualy makes a frame that i can parent my panel to.
Like ForteX Cooldownbar it doesn't make a named panel for it, so i can't parent my panel to it.

So i guess it's have to be done with the code Sniffles posted:
Code:
if IsAddOnLoaded("MyAddon") and MyFrameName:IsVisible() then
 MyFrame:Show()
end
I just can't seem how to make it correct.
  Reply With Quote
03-08-11, 10:36 AM   #8
zynix
A Cliff Giant
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 70
Originally Posted by frohanss View Post
Thx for the reply.
Maybe Recount was bad example to mention since it actualy makes a frame that i can parent my panel to.
Like ForteX Cooldownbar it doesn't make a named panel for it, so i can't parent my panel to it.

So i guess it's have to be done with the code Sniffles posted:
Code:
if IsAddOnLoaded("MyAddon") and MyFrameName:IsVisible() then
 MyFrame:Show()
end
I just can't seem how to make it correct.
Code:
if IsAddOnLoaded("Recount") and Addon:IsVisible() then
 Addon:Show()
end
That should work, though I can't check
  Reply With Quote
03-08-11, 11:35 AM   #9
frohanss
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 40
Ok, i got it to hide/show based on addon loaded:

Had to use:
Code:
if IsAddOnLoaded("Recount") and Addon:IsVisible() then
 Addon:Show()
 else
 Addon:Hide()
end
Also figured out the Slash command to toggle a panel (panel is called "Addon")
Code:
local show = false
SlashCmdList['Addon'] = function()
if show == false then
show = true
Addon:Show()
elseif show == true then
show = false
Addon:Hide()
end
end
SLASH_Addon1 = '/show'
Thx again all for the help.
  Reply With Quote
03-08-11, 01:21 PM   #10
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
you should try to use indentation
also shortened it up a bit
Code:
local show 

SlashCmdList["ADDON"] = function()
   if show then
      show = false
      Addon:Hide()
   else
      show = true
      Addon:Show()
   end
end

SLASH_ADDON1 = '/show'
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Few Question's regarding creating frames.


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