02-06-12, 02:54 AM | #1 |
Convert xml to lua
Can someone convert the following to LUA? Im not really sure whats going on here in xml... i went all lua early on... now this looks odd to me.
Code:
<?xml version="1.0"?> <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/"> <Frame name="AudioFrames" hidden="true" virtual="true" parent="UIParent"> <!-- set the parameters for the layers of the frame --> <Backdrop bgFile="Interface\TutorialFrame\TutorialFrameBackground" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true"> <EdgeSize> <AbsValue val="16"/> </EdgeSize> <TileSize> <AbsValue val="32"/> </TileSize> <BackgroundInsets> <AbsInset left="5" right="5" top="5" bottom="5"/> </BackgroundInsets> </Backdrop> </Frame> <Frame> <Frames> <Frame name="Audio_UI_Control" enableMouse="true" movable="true" hidden="false" inherits="AudioFrames"> <Size> <AbsDimension x="20" y="100"/> </Size> <Anchors> <Anchor point="LEFT"/> </Anchors> <Scripts> <OnMouseUp> if ( this.isMoving ) then this:StopMovingOrSizing(); this.isMoving = false; end </OnMouseUp> <OnMouseDown> if ( ( ( not this.isLocked ) or ( this.isLocked == 0 ) ) and ( arg1 == "LeftButton" ) ) then this:StartMoving(); this.isMoving = true; end </OnMouseDown> <OnHide> if ( this.isMoving ) then this:StopMovingOrSizing(); this.isMoving = false; end </OnHide> </Scripts> <Frames> <Frame name="$parent_Volume"> <Anchors> <Anchor point="BOTTOMLEFT" relativeTo="$parent" relativePoint="BOTTOMLEFT"> <Offset> <AbsDimension x="5" y="5"/> </Offset> </Anchor> <Anchor point="RIGHT" relativeTo="$parent" relativePoint="RIGHT"> <Offset> <AbsDimension x="-5" y="-5"/> </Offset> </Anchor> </Anchors> <Layers> <Layer level="BACKGROUND"> <Texture name="$parent_Background" setAllPoints="true"> <!-- Texture has blue color wit 50% alpha --> <Color r="0" g="1" b="1" a="0.5"/> </Texture> </Layer> </Layers> </Frame> <Button name="$parent_VolumeMask"> <Anchors> <Anchor point="BOTTOMLEFT" relativeTo="$parent" relativePoint="BOTTOMLEFT"> <Offset> <AbsDimension x="5" y="5"/> </Offset> </Anchor> <Anchor point="TOPRIGHT" relativeTo="$parent" relativePoint="TOPRIGHT"> <Offset> <AbsDimension x="-5" y="-5"/> </Offset> </Anchor> </Anchors> <Layers> <Layer level="ARTWORK"> <Texture name="$parent_Background" setAllPoints="true"> <!-- Texture has blue color wit 50% alpha --> <Color r="1" g="0" b="0" a="0.2"/> </Texture> </Layer> </Layers> </Button> </Frames> </Frame> <CheckButton name="Audio_UI_Mute" hidden="false"> <Size> <AbsDimension y="20"/> </Size> <Anchors> <Anchor point="TOPLEFT" relativeTo="Audio_UI_Control" relativePoint="BOTTOMLEFT"/> <Anchor point="TOPRIGHT" relativeTo="Audio_UI_Control" relativePoint="BOTTOMRIGHT"/> </Anchors> <NormalTexture name="$parent_Background" file="Interface\COMMON\VOICECHAT-SPEAKER"> </NormalTexture> <CheckedTexture name="$parent_Background" file="Interface\COMMON\VOICECHAT-MUTED"> </CheckedTexture> </CheckButton> </Frames> <Scripts> <OnLoad> Audio_OnLoad() </OnLoad> </Scripts> </Frame> </Ui> |
|
02-06-12, 06:15 AM | #2 |
That XML shouldn't even produce any visible frames... everything is parented to one frame that has no name (so no practical way to access it from code) and no position/dimensions (so it won't be shown anywhere, and neither will its children).
Also, that XML defined a template that was only used once, and did nothing besides set a backdrop for frames inheriting it, so I deemed it pointless and removed it. Otherwise, nothing changed. Several things did not make sense, or seemed vaguely wrong; those have been noted with comments in the code: Lua Code:
Also, not tested in-game, so beware of typos. |
|
02-06-12, 07:11 AM | #3 |
Phanx,
I take my helm off to you, for all your comprehensive answers in this forum. |
|
02-06-12, 07:20 AM | #4 |
Anything to avoid doing work while I'm at work.
|
|
02-06-12, 10:21 AM | #5 |
Haha
Thank you very much btw, makes much more sense now that its lua. It was really old code that may be part of what was wrong with it. |
|
02-06-12, 12:19 PM | #6 |
Pretty much any addon using XML for anything other than templates qualifies as "really old code", or at least code that has no excuse to be written at any point since all of the Lua frame methods were added in WoW 2.0 or something.
|
|
02-06-12, 04:54 PM | #7 |
btw, the book "World of Warcraft Programming" teaches to create almost everything with XML frames.
|
|
02-06-12, 06:57 PM | #8 |
Not everything, it has a section on lua. At least the first edition did. I have not seen the 2nd edition but i would imagine they touch even more on lua in it. It has both, but your right its initial take is to use xml. I recommend the book i found it helpful when i got started and its still a good reference. I had it... its in storage now but thats another story.
|
|
02-06-12, 08:05 PM | #9 |
Well, that book was originally published back in the Burning Crusade, and was most likely written well before that. It's the same with a lot of large, older addons that are still around... if it was originally written with XML, well, the XML still works, and it would be a lot of work to go back and rewrite it in pure Lua. I'm sure there's nothing wrong with the information in the book; it's just unnecessary extra stuff to learn.
Especially when you're just starting out with addon programming, I just don't see the point in having to learn two syntaxes when, in the vast majority of cases, XML is completely unnecessary and offers no real benefits over using Lua only. On the other hand, there are real benefits to using Lua only, such as the ability to create frames on demand, rather than only at load-time. For example, if you're building a list-like UI, you may not know how many list items you will need. Using XML, you would have to pick a maximum number, and create that many list items at login. If the user never needed that many list items, then all those extra frames are just occupying memory for no reason. If the user needs more list items, they're out of luck. Using Lua, you can start out with no list items sitting in memory, and create them on the fly as they are needed; this way, the user can have as many list items as they need, and never has to dedicate resources to list items they don't need. You could, theoretically, define a "template" list item in XML, and then generate copies of it as needed in Lua, but if you're already doing that, why bother with the XML at all? Plus, XML is ridiculously verbose... in this thread, the original XML is twice as many lines of code as its equivalent in pure Lua. Less scrolling = better readability. |
|
WoWInterface » Developer Discussions » Lua/XML Help » Convert xml to lua |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|