魔兽世界插件三部曲之二 ---- XML
摘要: 首先确定你要无比热爱WOW,热爱UI,热爱DIY~~否则大量的脚本及相关的知识只会将你的自信心淹没,以至于还未着手深入了解、学习就轻言放弃,其次你可能先需要了解一些基本的编程知识,因为开发一些自定义脚本是需要学习一些编程语言基础的,虽然不用学的很深奥,但基本的语句用法还是要理解的。如果你具备这些条件那么就接着往下看。
之前给大家介绍了TOC的相关知识,相信有心看过的玩家应该已经基本了解可以自己编写自己的TOC了,接下来给大家介绍的插件3大组成部分之二——"XML" 定义:
XML为 eXtensible Markup Language 的缩写。eXtensible Markup Language中文译为“可扩展标记语言”,为众多Markup Language中的一种。其主要的目标为建立一种更加简单的结构更加严谨的SGML(Standard Generalized Markup Language,标准通用标记语言)。
而WoW使用XML来定义规划游戏界面元素。
一个简单的实体定义档XML格式如下:
<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/"
>
<script file="脚本文件.lua"/>
<Frame name="唯一的编号">
<scripts>
<OnLoad>
this:RegisterEvent("注册变量");
</OnLoad>
<OnEvent>
if (event == "注册的变量名") then
"调用自定义函数";
end
</OnEvent>
</scripts>
</Frame>
</Ui>
〓XML用户界面〓
魔兽世界有一个相当强大的创建用户界面的布局引擎。当组合一个附着UI 元素行为的的LUA脚本时,就创建了一个灵活、完整的游戏UI,这可以很好的创建一个自定义的插件。为了能让这些程序正确的执行,那么至少应该在Interface 目录下包含一个FrameXml 目录。(这个目录默认是隐藏的,你可以通过WinMpq软件打开Interface.mpq来找到这个文件夹)
一个XML文件是一个包含了起始和结束标记元素的集合,一个用户界面描述文件也不例外。在一个用户界面的XML中有2 种主要的元素类型。第一个类型用于声明一个用户界面中的部件,如按钮、框架、复选框,我们称其为部件元素。第二个元素类型总是出现在第一个元素类型的内部,用于定义部件的属性和行为,我们称其为属性元素。下面是一个例子:
<Button name="MyAddon_Button">
<Anchors>
<Anchor point="CENTER"/>
</Anchors>
</Button>
在这里Button 元素是第一个类型元素,也就是说是一个部件元素。它出现在这个XML文件中促使一个名为MyButton的按钮被创建。这个元素内部中的Anchors定义了它的属性,因此这些是第二个元素类型,也就是说是一个属性元素。一般的UI 结构总是这样的,你使用一个元素来表现一个部件,并且在其内部使用其他元素来表现它的属性。并且他们是可以嵌套的,举个例子:
- BACKGROUND - Level 0. Place the background of your frame here.
- BORDER - Level 1. Place the artwork of your frame here .
- ARTWORK - Level 2. Place the artwork of your frame here.
- OVERLAY - Level 3. Place your text, objects, and buttons in this level
- HIGHLIGHT - Level 4. Place your text, objects, and buttons in this level
复制代码
Elements in the HIGHLIGHT Layer are automatically shown or hidden when the mouse enters or leaves! For Highlighting to work you need enableMouse="true" in your <Frame> attributes.
注意:以上大写的原因表示该属性作用未知。看下面的例子:
- ·OnAnimFinished
- ·OnChar
- ·OnClick
- ·OnColorSelect
- ·OnCursorChanged
- ·OnDoubleClick
- ·OnDragStart
- ·OnDragStop
- ·OnEditFocusGained
- ·OnEditFocusLost
- ·OnEnter</FONT></FONT></FONT></FONT><FONT style="FONT-FAMILY: 宋体"><FONT size=3>
- <FONT color=navy>·OnEnterPressed
- ·OnEscapePressed
- ·OnEvent
- ·OnFocusGained
- ·OnFocusLost
- ·OnHide
- ·OnHorizontalScroll
- ·OnHyperlinkClick
- ·OnHyperlinkEnter
- ·OnHyperlinkLeave
- ·OnInputLanguageChanged
- ·OnKeyDown
- ·OnKeyUp
- ·OnLeave
- ·OnLoad
- ·OnMessageScrollChanged
- ·OnMouseDown
- ·OnMouseUp
- ·OnMouseWheel
- ·OnMovieFinished
- ·OnMovieHideSubtitle
- ·OnMovieShowSubtitle
- ·OnReceiveDrag
- ·OnScrollRangeChanged
- ·OnShow
- ·OnSizeChanged
- ·OnSpacePressed
- ·OnTabPressed
- ·OnTextChanged
- ·OnTextSet
- ·OnUpdate
- ·OnUpdateModel
- ·OnValueChanged
- ·OnVerticalScroll</FONT></FONT></FONT><FONT color=navy>
复制代码
你应该注意以上事件主要包括与用户界面有关系的事件,OnEvent 事件是个特殊的事件,它是一些事件的集合。它能调用与游戏有关的事件。
10) Widget Elements 部件元素
这里大多数信息来自UI.xsd,这不意味着完整,因为任何时候都可能发生变化。部件元素具有等级关系,一些元素可能派生自其他元素。这意味着派生的元素继承了它父元素的属性和属性元素。继承也同样适用于该类型部件的API 函数。
Tip:这个等级不受其父子关系的影响,也同样不影响继承模板(虚拟元素)。
UI LayoutFrame
在XML文件中,无论哪个部件元素可指定,你都应该使用派生自它的元素来作为使用
的部件。在下面的参考中,将使用一对大括号{}指示该部分可替换。
UI
LayoutFrame Elements: Size, Anchors
Attributes: name, inherits, virtual, setAllPoints, hidden
Texture
Derived from: LayoutFrame
Elements: TexCoords, Color, Gradient
Attributes: file, alphaMode
Note: The Texture must be within a <Layer>
Note #2: When adding custom textures remember that the file must have power-of-two dimensions, or else you'll end up with a solid green texture. For reference: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048... You can always cut off any excess size with TexCoords.
FontStringDerived from: LayoutFrame Elements: FontHeight, Color, Shadow Attributes: font, bytes, text, spacing, outline, monochrome, nonspacewrap, justifyV, justifyH, maxLines, inherits The Fontstring element is used to display a text in the user interface. The text displayed by the Fontstring element can be changed with the LUA function <fontstringobject>:SetText() or read with the function <fontstringobject>:GetText(). outline = "NORMAL" or "THICK", m or "false", justifyV = "TOP", "MIDDLE" or "BOTTOM", justifyH = "LEFT", "RIGHT", "CENTER" inherits can be set to an existing font. If set, the current FontString will take on all of that font's settings, unless overridden in the current FontString. Note: <FontString> must be within a <Layer>, Attribute "font" needs to be set for element "FontHeight" to work 【外部图片】See FrameXML/Fonts.xml for the system default list of inheritable fonts! Code: FontString Widget API
Example - Derived from: <A href="http://www.wowwiki.com/XML_User_Interface#LayoutFrame" target=_blank><FONT color=#002bb8>LayoutFrame</FONT></A> Elements: <A href="http://www.wowwiki.com/index.php?title=XML/Frame/TitleRegion&action=edit&redlink=1" target=_blank><FONT color=#ba0000>TitleRegion</FONT></A>, ResizeBounds, <A href="http://www.wowwiki.com/XML/Frame/Backdrop" target=_blank><FONT color=#002bb8>BackDrop</FONT></A>, <A href="http://www.wowwiki.com/XML/Frame/HitRectInsets" target=_blank><FONT color=#002bb8>HitRectInsets</FONT></A>, Layers, Frames, Scripts, <A href="http://www.wowwiki.com/XML/Frame/BackDrop/BackgroundInsets" target=_blank><FONT color=#002bb8>BackgroundInsets</FONT></A> Attributes: <A href="http://www.wowwiki.com/XML/Frame/alpha" target=_blank><FONT color=#002bb8>alpha</FONT></A>, parent, <A href="http://www.wowwiki.com/XML/Frame/toplevel" target=_blank><FONT color=#002bb8>toplevel</FONT></A>, movable, resizable, <A href="http://www.wowwiki.com/XML/Frame/frameStrata" target=_blank><FONT color=#002bb8>frameStrata</FONT></A>, <A href="http://www.wowwiki.com/XML/Frame/frameLevel" target=_blank><FONT color=#002bb8>frameLevel</FONT></A>, id, enableMouse, enableKeyboard
复制代码 ButtonDerived from: Frame Elements: NormalTexture, PushedTexture, DisabledTexture, HighlightTexture, NormalText, HighlightText, DisabledText, PushedTextOffset Attributes: text Notes: The various textures, once inherited or set to art of your choice, will automatically behave as expect. (highlight on mouseover, pushed while clicked, disabled when disabled) The same goes for the different texts.
Example
Included in Backdrop- Derived from: <A href="http://www.wowwiki.com/XML_User_Interface#Button" target=_blank><FONT color=#002bb8>Button</FONT></A>
- Elements: CheckedTexture, DisabledCheckedTexture
- Attributes: checked
- Note: For checkbuttons, setting the label of the checkbutton works differently from normal buttons. Using MyCheckButton:SetText("monkey"); will not give you a visible result. Instead, you need to address the text property of the checkbuttons invisible FontString frame. The FontString frame is named "<checkButtonName>Text", so to address it, use the following lua code: getglobal(MyCheckButton:GetName() .. "Text"):SetText("Monkey");
复制代码
Example
Included in Backdrop
- Derived from: <A href="http://www.wowwiki.com/XML_User_Interface#Frame" target=_blank><FONT color=#002bb8>Frame</FONT></A> Elements: BarTexture, BarColor Attributes: <A href="http://www.wowwiki.com/XML/StatusBar/drawLayer" target=_blank><FONT color=#002bb8>drawLayer</FONT></A>, minValue, maxValue, defaultValue
复制代码
Slider
Derived from: Frame Elements: ThumbTexture Attributes: drawLayer, minValue, maxValue, defaultValue, valueStep, orientation EditBox Derived from: Frame
Elements: FontString, HighlightColor, TextInsets
Attributes: letters, blinkSpeed, numeric, password, multiLine, historyLines, autoFocus, ignoreArrows
Example Included in Backdrop- Derived from: <A href="http://www.wowwiki.com/XML_User_Interface#Frame" target=_blank><FONT color=#002bb8>Frame</FONT></A>
- Elements: ColorWheelTexture, ColorWheelThumbTexture, ColorValueTexture, ColorValueThumbTexture
复制代码
Example
Included in Backdrop- Derived from: <A href="http://www.wowwiki.com/XML_User_Interface#Frame" target=_blank><FONT color=#002bb8>Frame</FONT></A> Elements: FogColor Attributes: file, scale, fogNear, fogFar
复制代码 SimpleHTML
Derived from: Frame Elements: FontString, FontStringHeader1, FontStringHeader2, FontStringHeader3 Attributes: files MessageFrame Derived from: Frame Elements: FontString, TextInsets Attributes: fadeDuration, insertMode
ScrollingMessageFrame Derived from: Frame Elements: FontString, TextInsets Attributes: fade, fadeDuration, displayDuration, maxLines ScrollFrame Derived from: Frame Elements: ScrollChild MovieFrame
GameTooltip
For a Lua pseudo code representation of the tooltip widget's methods, see Tooltip Pseudo Code Derived from: Frame Elements: ? Attributes: ?
TaxiRouteFrame Derived from: Frame Elements: ? Attributes: ?
LootButton Derived from: Button Elements: ? Attributes: ?
TabardModel PlayerModel
Derived from: Model Elements: ? Attributes: ? Minimap Derived from: Frame Elements: ? Attributes: ? WorldFrame
Derived from: Frame
Elements: ?
Attributes: ?
|