11-05-20, 11:19 PM | #1 |
Transforming ".xml" to ".lua"
Hello friends,
I'm having trouble turning a ".xml" code ".lua". XML code is ... Code:
<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="DerangementPetBattleCooldowns.lua"/> <Frame name="DeePetBattleAuraTemplate" virtual="true"> <Size x="33" y="32"/> <Layers> <Layer level="ARTWORK"> <Texture parentKey="Icon"> <Size x="30" y="30"/> <Anchors> <Anchor point="CENTER" relativeKey="$parent" relativePoint="CENTER" x="0" y="0"/> </Anchors> </Texture> </Layer> <Layer level="OVERLAY"> <FontString parentKey="Duration" inherits="GameFontHighlight" justifyH="CENTER" justifyV="TOP"> <Anchors> <Anchor point="TOPLEFT" relativePoint="BOTTOMLEFT" x="0" y="0"/> <Anchor point="TOPRIGHT" relativePoint="BOTTOMRIGHT" x="0" y="0"/> <Anchor point="BOTTOM" relativePoint="BOTTOM" x="0" y="-16"/> </Anchors> </FontString> <Texture parentKey="DebuffBorder" file="Interface\Buttons\UI-Debuff-Overlays"> <Size> <AbsDimension x="33" y="32"/> </Size> <Anchors> <Anchor point="CENTER" relativeKey="$parent.Icon" relativePoint="CENTER"/> </Anchors> <TexCoords left="0.296875" right="0.5703125" top="0" bottom="0.515625"/> <Color r="1" g="0" b="0"/> </Texture> </Layer> </Layers> <Scripts> <OnEnter function="DeePetBattleAura_OnEnter"/> <OnLeave function="DeePetBattleAura_OnLeave"/> </Scripts> </Frame> <Button name="DeePetBattleAbilityButtonTemplate" inherits="PetBattleActionButtonTemplate" motionScriptsWhileDisabled="true" virtual="true"> <Frames> <!-- these auxiliary frames are used only as anchor points, and to check which half-button the mouse is over --> <Frame parentKey="topHalf"> <Anchors> <Anchor point="TOPLEFT"/> <Anchor point="BOTTOMRIGHT" relativePoint="RIGHT"/> </Anchors> <Scripts> <OnEnter function="DeePetBattleAbilityButton_topHalf_OnEnter"/> <OnLeave function="DeePetBattleAbilityButton_OnLeave"/> </Scripts> </Frame> <Frame parentKey="bottomHalf"> <Anchors> <Anchor point="TOPLEFT" relativePoint="LEFT"/> <Anchor point="BOTTOMRIGHT"/> </Anchors> </Frame> </Frames> <Layers> <Layer level="BACKGROUND" textureSubLevel="1"> <Texture parentKey="Icon2"> <TexCoords left="0" right="1" top="0" bottom="0.5" /> <Anchors> <Anchor point="TOPLEFT"/> <Anchor point="BOTTOMRIGHT" relativePoint="RIGHT"/> </Anchors> </Texture> </Layer> <Layer level="BORDER"> <Texture parentKey="topHalfBorder" file="Interface\Buttons\UI-Quickslot2"> <TexCoords left="0.1953125" right="0.7890625" top="0.625" bottom="0.7734375" /> <Anchors> <Anchor point="TOPLEFT" relativePoint="LEFT" relativeKey="$parent.topHalf"/> <Anchor point="BOTTOMRIGHT" relativePoint="RIGHT"/> </Anchors> </Texture> <Texture parentKey="bottomHalfBorder" file="Interface\Buttons\UI-Quickslot2"> <TexCoords left="0.1953125" right="0.7890625" top="0.7734375" bottom="0.625" /> <Anchors> <Anchor point="TOPLEFT" relativePoint="LEFT"/> <Anchor point="BOTTOMRIGHT" relativePoint="RIGHT" relativeKey="$parent.bottomHalf"/> </Anchors> </Texture> </Layer> <Layer level="OVERLAY" textureSubLevel="-1"> <FontString parentKey="Duration" inherits="GameFontHighlightLarge" justifyH="CENTER" justifyV="TOP"> <Anchors> <Anchor point="LEFT"/> <Anchor point="RIGHT"/> <Anchor point="TOP" relativePoint="BOTTOM" x="0" y="-2"/> <Anchor point="BOTTOM" relativePoint="BOTTOM" x="0" y="-18"/> </Anchors> </FontString> <Texture parentKey="AuraBorder" file="Interface\Buttons\UI-Debuff-Overlays"> <Size> <AbsDimension x="57" y="55"/> </Size> <Anchors> <Anchor point="CENTER" relativeKey="$parent.Icon" relativePoint="CENTER"/> </Anchors> <TexCoords left="0.296875" right="0.5703125" top="0" bottom="0.515625"/> </Texture> </Layer> <Layer level="OVERLAY"> <Texture parentKey="BetterIcon2" file="Interface\PetBattles\BattleBar-AbilityBadge-Weak" hidden="true"> <Size x="32" y="32"/> <Anchors> <Anchor point="TOPRIGHT" x="9" y="9"/> </Anchors> </Texture> </Layer> </Layers> <Scripts> <OnLoad function="DeePetBattleAbilityButton_OnLoad"/> <OnEvent function="DeePetBattleAbilityButton_OnEvent"/> <OnEnter function="DeePetBattleAbilityButton_OnEnter"/> <OnLeave function="DeePetBattleAbilityButton_OnLeave"/> </Scripts> <NormalTexture parentKey="NormalTexture" file="Interface\Buttons\UI-Quickslot2"> <TexCoords left="0.1953125" right="0.7890625" top="0.1953125" bottom="0.7890625" /> </NormalTexture> <PushedTexture file="Interface\Buttons\UI-Quickslot2"> <TexCoords left="0.1953125" right="0.7890625" top="0.1953125" bottom="0.7890625" /> </PushedTexture> <HighlightTexture/> </Button> <Frame name="DeePetBattleAbilityGroupTemplate" virtual="true"> <Frames> <Button parentKey="Button1" inherits="DeePetBattleAbilityButtonTemplate"> <Anchors> <Anchor point="LEFT" relativePoint="LEFT"/> </Anchors> </Button> <Button parentKey="Button2" inherits="DeePetBattleAbilityButtonTemplate"> <Anchors> <Anchor point="CENTER" relativePoint="CENTER"/> </Anchors> </Button> <Button parentKey="Button3" inherits="DeePetBattleAbilityButtonTemplate"> <Anchors> <Anchor point="RIGHT" relativePoint="RIGHT"/> </Anchors> </Button> </Frames> <Scripts> <OnLoad function="DeePetBattleAbilityGroup_OnLoad"/> </Scripts> </Frame> <Frame name="DeePetBattlePetTemplate" virtual="true"> <Size> <AbsDimension x="115" y="36"/> </Size> <Frames> <Frame parentKey="Abilities" inherits="DeePetBattleAbilityGroupTemplate" setAllPoints="true"/> </Frames> <Scripts> <OnLoad function="DeePetBattlePet_OnLoad"/> <OnEvent function="DeePetBattlePet_OnEvent"/> <OnShow function="DeePetBattlePet_OnShow"/> </Scripts> </Frame> <Frame name="DeePetBattleAllyPetTemplate" inherits="DeePetBattlePetTemplate" virtual="true"> <Frames> <Frame parentKey="Auras"> <Frames> <Frame parentkey="NextFrame" inherits="DeePetBattleAuraTemplate" hidden="true"> <Anchors> <Anchor point="RIGHT" relativePoint="RIGHT" x="0" y="0"/> </Anchors> </Frame> </Frames> <Anchors> <Anchor point="TOPRIGHT" relativePoint="TOPLEFT" relativeKey="$parent.Abilities" x="-6" y="0"/> <Anchor point="BOTTOMRIGHT" relativePoint="BOTTOMLEFT" relativeKey="$parent.Abilities" x="-6" y="0"/> <Anchor point="LEFT" relativePoint="LEFT" relativeTo="UIParent"/> </Anchors> </Frame> </Frames> </Frame> <Frame name="DeePetBattleEnemyPetTemplate" inherits="DeePetBattlePetTemplate" virtual="true"> <Frames> <Frame parentKey="Auras"> <Frames> <Frame parentkey="NextFrame" inherits="DeePetBattleAuraTemplate" hidden="true"> <Anchors> <Anchor point="LEFT" relativePoint="LEFT" x="0" y="0"/> </Anchors> </Frame> </Frames> <Anchors> <Anchor point="TOPLEFT" relativePoint="TOPRIGHT" relativeKey="$parent.Abilities" x="6" y="0"/> <Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT" relativeKey="$parent.Abilities" x="6" y="0"/> <Anchor point="RIGHT" relativePoint="RIGHT" relativeTo="UIParent"/> </Anchors> </Frame> </Frames> </Frame> <Frame name="DeePetBattleFrame" parent="PetBattleFrame"> <Scripts> <OnLoad function="DeePetBattleFrame_OnLoad"/> <OnEvent function="DeePetBattleFrame_OnEvent"/> <OnShow function="DeePetBattleFrame_OnShow"/> </Scripts> <Frames> <Frame parentkey="Ally1" inherits="DeePetBattlePetTemplate"> <Anchors> <Anchor point="TOPLEFT" relativeKey="$parent.$parent.ActiveAlly" relativePoint="TOPRIGHT" x="30" y="2"/> </Anchors> <Scripts> <OnLoad> DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ALLY, 1); </OnLoad> </Scripts> </Frame> <Frame parentkey="Ally2" inherits="DeePetBattleAllyPetTemplate"> <Anchors> <Anchor point="RIGHT" relativeKey="$parent.$parent.Ally2" relativePoint="LEFT" x="-7" y="0"/> </Anchors> <Scripts> <OnLoad> DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ALLY, 2); </OnLoad> </Scripts> </Frame> <Frame parentkey="Ally3" inherits="DeePetBattleAllyPetTemplate"> <Anchors> <Anchor point="RIGHT" relativeKey="$parent.$parent.Ally3" relativePoint="LEFT" x="-7" y="0"/> </Anchors> <Scripts> <OnLoad> DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ALLY, 3); </OnLoad> </Scripts> </Frame> <Frame parentkey="Enemy1" inherits="DeePetBattlePetTemplate"> <Anchors> <Anchor point="TOPRIGHT" relativeKey="$parent.$parent.ActiveEnemy" relativePoint="TOPLEFT" x="-30" y="2"/> </Anchors> <Scripts> <OnLoad> DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ENEMY, 1); </OnLoad> </Scripts> </Frame> <Frame parentkey="Enemy2" inherits="DeePetBattleEnemyPetTemplate"> <Anchors> <Anchor point="LEFT" relativeKey="$parent.$parent.Enemy2" relativePoint="RIGHT" x="7" y="0"/> </Anchors> <Scripts> <OnLoad> DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ENEMY, 2); </OnLoad> </Scripts> </Frame> <Frame parentkey="Enemy3" inherits="DeePetBattleEnemyPetTemplate"> <Anchors> <Anchor point="LEFT" relativeKey="$parent.$parent.Enemy3" relativePoint="RIGHT" x="7" y="0"/> </Anchors> <Scripts> <OnLoad> DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ENEMY, 3); </OnLoad> </Scripts> </Frame> </Frames> </Frame> </Ui> |
|
11-05-20, 11:40 PM | #2 |
As far as I know you can't create templates in code.
The rest can be gleaned from browsing the wowpedia site for script code examples. Here is the HOWTO page that provides a few examples of what you might want to do in addons, there are a few frame related examples which will hopefully get you started. https://wow.gamepedia.com/HOWTOs And this link gets you to the CreateFrame page with some additional examples: https://wow.gamepedia.com/API_CreateFrame Is there a reason you need this in lua format ?
__________________
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 |
|
11-06-20, 09:49 AM | #3 |
There is nothing wrong with using XML. If someone else has already created a template you want to use then it's a waste of effort duplicating it in any fashion. Once the widget has been created, it all ends up being the same in-game no matter the method used "read its parts and glue it together".
That said, you can use lua functions to build up widgets just as you would in XML. The "virtual" attribute means "Don't create unless specifically used" just like a function does nothing unless called. Lua Code:
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 11-06-20 at 10:03 AM. |
|
11-06-20, 04:00 PM | #4 |
In certain narrow cases, XML is 'mandatory' if you need to absolutely need to create an XML template. Examples would be pins on the 8.0.1 world map; I don't think that can be done without an XML file (that is just three lines long).
Otherwise... you just have to go from this paradigm: Code:
<Frame name="MyTemplate" virtual="true" hidden="true"> <Scripts> <OnShow> print("see me now?") </OnShow> </Script> <!-- insert other stuff here to control its appearance --> </Frame> <Frame name="MyFrame1" implements="MyTemplate" id="1"></Frame> <Frame name="MyFrame2" implements="MyTemplate" id="2"></Frame> <Frame name="MyFrame3" implements="MyTemplate" id="3"></Frame> To this one: Lua Code:
But I would echo Fizzlemizz's remarks... there's nothing wrong with leaving something in XML if its already done. Therefore, I would only advise converting it to Lua if you were making a more substantial change in the process. |
|
11-06-20, 04:20 PM | #5 |
The only time you need to consume an xml template is if you require something to work with the secure environment but that can be done in xml or lua.
Intrinsics would need to be created in XML but calling a function mimics doing that also.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 11-06-20 at 04:23 PM. |
|
11-06-20, 05:03 PM | #6 |
I never thought of templates in xmls as the equivalent of functions that create frames .. *doh* ..
However, although I can't find the source, I am sure I read somewhere that xml files load faster than lua files. Of course I may have imagined it rofl. But it did make me convert some of my rewritten addons to xml based frames with lua handling the functionality. Whether small addons will notice the difference if this is true, I am sure bigger addons will.
__________________
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 |
|
11-06-20, 05:42 PM | #7 |
Optimised for XML in 2004 and 2020, the noticeable difference is probably minimal these days, unless you have something creating lots frames at runtime. The largest single "batch" of frames are created before you see your character in-game.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 11-08-20 at 01:16 AM. |
|
11-08-20, 11:54 AM | #8 |
"The only time you need to consume an xml template"
--- It can also be the case if you are interfacing with Blizzard's code that assumes a template. For example, the world map will acquire pins using the name of the template for each pin type. Of course, you could build your own world map that overrides this -- but that's a lot more work! So I guess I cannot fairly say the XML is 'mandatory' but perhaps 'most appropriate' for certain situations. |
|
11-08-20, 08:20 PM | #9 |
To create template in Lua, we should use classes, it's not a simple job to fulfill all requirements.
I can do that with my PLoop and Scorpio Lib, but normally only authors with full OOP background can follow that. So this is only an example for the first two template. Lua Code:
The doc can be found at github.com/kurapica/Scorpio, if you want give it a try. |
|
WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Transforming ".xml" to ".lua" |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|