lua & xml

lua & xml

by cyklon » Sat Jan 02, 2016 11:19 am

need some help creating a frame and if i understand things correct i must create the frame in xml and call for the frame in lua.

there is something im missing in the code but i dont know what it is..

*.lua coding
Code: Select all
local f = CreateFrame("customframe",nil,UIParent)
   f:SetFrameStrata("BACKGROUND")
   f:SetWidth(128)
   f:SetHeight(64)

local t = f:CreateTexture(nil,"BACKGROUND")
   t:SetTexture("blablabla.tga")
   t:SetAllPoints(f)
   f.texture = t

   f:SetPoint("CENTER",0,0)
   f:Show()
end


*.xml coding
Code: Select all
<Ui xmlns="http://www.blizzard.com/wow/ui/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
<Script File="luapath.lua"/>
<Frame name="customframe">
  <Anchors>
    <Anchor point="CENTER"/>
  </Anchors>
  <Frames>
    <Frame name="customframe">
      <Anchors>
        <Anchor point="CENTER"/>
      </Anchors>
    </Frame>
  </Frames>
</Frame>
 </Ui>
User avatar
cyklon
Senior Sergeant
Senior Sergeant
 

Re: lua & xml

by Mimma » Sat Jan 02, 2016 11:23 am

What error are you getting?
Image
User avatar
Mimma
Legionnaire
Legionnaire
 

Re: lua & xml

by modernist » Sat Jan 02, 2016 11:34 am

you can use actually xml or lua to create a frame, and in this case you are actually doing the same creation job twice — overwriting whichever of the first you load by reusing the same name across your two files.

I personally find pure lua implementation to be a much cleaner and more effective method with less overhead, so I'd recommend:

Code: Select all
local f = CreateFrame("customframe", nil, UIParent)
f:SetFrameStrata("BACKGROUND")
f:SetWidth(128)
f:SetHeight(64)
f:SetPoint("CENTER", 0, 0)
f:SetBackdrop({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]]})
f:SetBackdropColor(0, 0, 0, 1)

local t = f:CreateTexture(nil,"BACKGROUND")
t:SetTexture("blablabla.tga")
t:SetAllPoints()
f.texture = t


no need to call Show() as that is the default state on a frames creation. you can also call SetAllPoints() without an argument focus like this, and it'll default to the point references of the childs parent.

finally — you've not created a function or any kind of scoping, so no need to drop an 'end' at the foot of your file. that'll actually cause a lua error and is probably the reason your frame isn't showing up. i'd recommend turning on 'show lua errors' in your interface options if its currently toggled off.

someone else can probably give you a better overview of xml usage.

e: also note that custom textures have some rules that need to be followed — the most important of which is that the image must be saved at a size that is a power of 2 (2px, 4px, 8px, 16px, 32px, 64px, 128px etc.). i've taken the liberty of adding two more lines that add a simple backdrop to the frame (similar to that applied to tooltips or other blizzard elements), which will show up if the frame is created but your texture fails to successfully appear, for bug testing. you can remove those lines again once it is sorted.
modernist
Sergeant Major
Sergeant Major
 

Re: lua & xml

by cyklon » Sat Jan 02, 2016 11:49 am

That was quick replys, thanks, ill stick to lua then,, much easier to understand IMO :)
User avatar
cyklon
Senior Sergeant
Senior Sergeant
 

Re: lua & xml

by Geigerkind » Sat Jan 02, 2016 1:08 pm

It really depends what you want to achieve in the end:
If you just want a frame that handles events, a frame that is created by lua is perfect for the job whereas if you want to create a whole interface, xml might be the better choice for you.

This is such an interface for example:
Image
My Addons:
DPSMate - A combat analyzation tool (/viewtopic.php?f=63&t=38042)
Vanilla Consolidated Buff-Frames (/viewtopic.php?f=63&t=18189)
Modified Power Auras (/viewtopic.php?f=63&t=18251)
User avatar
Geigerkind
Senior Sergeant
Senior Sergeant
 

Re: lua & xml

by cyklon » Sat Jan 02, 2016 1:28 pm

i'm creating a frame(s) that will servs as an anchor for diffrent addons, now i just have to figure how to show the frames by typing a command and hiding them again by using a command again.
User avatar
cyklon
Senior Sergeant
Senior Sergeant
 

Re: lua & xml

by Geigerkind » Sat Jan 02, 2016 1:54 pm

My Addons:
DPSMate - A combat analyzation tool (/viewtopic.php?f=63&t=38042)
Vanilla Consolidated Buff-Frames (/viewtopic.php?f=63&t=18189)
Modified Power Auras (/viewtopic.php?f=63&t=18251)
User avatar
Geigerkind
Senior Sergeant
Senior Sergeant
 

Re: lua & xml

by cyklon » Sat Jan 02, 2016 1:58 pm

heheh,, ye, i found it earlier and trying to figure it out :) THANKS!
User avatar
cyklon
Senior Sergeant
Senior Sergeant
 

Re: lua & xml

by modernist » Sat Jan 02, 2016 2:11 pm

cyklon wrote:i'm creating a frame(s) that will servs as an anchor for diffrent addons, now i just have to figure how to show the frames by typing a command and hiding them again by using a command again.


Code: Select all
SLASH_ADDON1 = '/addon'
SlashCmdList['ADDON'] = function(arg)
    if f:IsShown() then f:Hide() else f:Show() end
end
modernist
Sergeant Major
Sergeant Major
 

Re: lua & xml

by cyklon » Sat Jan 02, 2016 2:13 pm

LOVE YOU! Thanks
User avatar
cyklon
Senior Sergeant
Senior Sergeant
 

Next

Return to Addons & macros

cron