参考了:cegui 魔兽世界 迅雷 mygui
主要问题如下:
Q1: 控件的属性是放到xml节点的属性中,还是作为子节点。放到属性中方便,但是xml太长,人眼看的时候费劲,子节点会好很多。
Q2: 控件之间的父子关系是直接用xml的节点父子关系来表达,还是和魔兽世界一样允许
parent="UIParent",这样设置。我可能还需要“include”其他xml中定义的控件?
直接xml父子节点:优势是关系简单明了,缺陷是UI复杂以后堆积的xml文件太长,人眼也无法看明白了
魔兽世界:他们的做法可以分离每个控件出来,但是层次关系又不明朗了。
允许类似<Window></InsertControlByName name="ChirdControl" type="Type"></Window>这样的特殊节点,平衡两者有优劣势。但是名字空间还是需要非常留意的点。
另外可以支持<ExportControls></Window name="ExportWnd"></ExportControls>,<InportControls></InportControl name="Import" type="Type" ImportFile="xxx.xml"><InportControls>
type属性不必要,但是加上以后可以让xml自校验能力更强
解决名字冲突还是没什么办法。但是库必须提供名字无关的控件消息绑定手段!允许全局重复名字的控件
<GUILayout version="4" >
<Window type="Generic/Image" name="GameOverRoot" >
<Property name="Area" value="{{0,0},{0,0},{1,0},{1,0}}" />
<Property name="Image" value="HUDDemo/Filler" />
<Property name="MaxSize" value="{{1,0},{1,0}}" />
<Property name="AlwaysOnTop" value="True" />
<Property name="ImageColours" value="tl:88888888 tr:88888888 bl:88888888 br:88888888" />
<Window type="Generic/Image" name="GameOverImage" >
<Property name="Area" value="{{0,0},{0.119444,0},{0,0},{0.519444,0}}" />
<Property name="MaxSize" value="{{1,0},{1,0}}" />
<Property name="AspectMode" value="Expand" />
<Property name="AspectRatio" value="1.923" />
<Property name="HorizontalAlignment" value="Centre" />
</Window>
<Window type="Generic/ImageButton" name="ButtonRestart" >
<Property name="Area" value="{{0,0},{0.597222,0},{0.153906,0},{0.661111,0}}" />
<Property name="HoverImage" value="HUDDemo/ButtonNormal" />
<Property name="NormalImage" value="HUDDemo/ButtonNormal" />
<Property name="PushedImage" value="HUDDemo/ButtonPressed" />
<Property name="DisabledImage" value="HUDDemo/ButtonNormal" />
<Property name="HorizontalAlignment" value="Centre" />
<Window type="Generic/Label" name="LabelRestart" >
<Property name="Area" value="{{0,0},{0.152778,0},{1,0},{1,0}}" />
<Property name="Font" value="GreatVibes-22" />
<Property name="Text" value="Restart" />
<Property name="MaxSize" value="{{1,0},{1,0}}" />
<Property name="NormalTextColour" value="FFFFFFFF" />
<Property name="DisabledTextColour" value="FFFFFFFF" />
<Property name="MousePassThroughEnabled" value="True" />
</Window>
</Window>
</Window>
</GUILayout>
<Framename="EnterLeaveTest" parent="UIParent">
<Size x="100" y="100" />
<Anchors>
<Anchor point="CENTER"relativePoint="CENTER" relativeTo="UIParent" />
</Anchors>
<Layers>
<Layer level="BACKGROUND">
<Texture name="$parentIcon"file="Interface\Icons\Spell_ShadowWordPain" setAllPoints="true"/>
</Layer>
</Layers>
<Scripts>
<OnEnter>
ChatFrame1:AddMessage("++ 进入窗体:" .. self:GetName())
</OnEnter>
<OnLeave>
ChatFrame1:AddMessage("-- 离开窗体:" .. self:GetName())
</OnLeave>
</Scripts>
</Frame>
<xlue>
<control class="BoltFox.MainMenu.Item">
<attr_def>
<attr name="SubMenuTemplate" type="string"/>
<attr name="Text" type="string"/>
</attr_def>
<method_def>
<SetContainer file="MainMenu.xml.lua" func="MainMenu_Item_SetContainer"/>
<PopupSubMenu file="MainMenu.xml.lua" func="MainMenu_Item_PopupSubMenu"/>
<DestroySubMenu file="MainMenu.xml.lua" func="MainMenu_Item_DestroySubMenu"/>
<SetEntered file="MainMenu.xml.lua" func="MainMenu_Item_SetEntered"/>
<SetText file="MainMenu.xml.lua" func="MainMenu_Item_SetText"/>
<GetText file="MainMenu.xml.lua" func="MainMenu_Item_GetText"/>
</method_def>
<event_def>
<OnSelected />
</event_def>
<objtemplate>
<children>
<obj id="root" class="LayoutObject">
<attr>
<left>0</left>
<top>0</top>
<width>father.width</width>
<height>father.height</height>
</attr>
<children>
<obj id="hoverBkg" class="FillObject">
<attr>
<left>0</left>
<top>0</top>
<width>father.width</width>
<height>father.height</height>
<visible>false</visible>
<filltype>singlecolor</filltype>
<srccolor>235,0,0,155</srccolor>
</attr>
<children>
<obj id="tosub" class="ImageObject">
<attr>
<left>10</left>
<top>4</top>
<width>father.width - 10</width>
<height>5</height>
<visible>false</visible>
<image>bitmap.right.triangle</image>
</attr>
</obj>
<obj id="text" class="TextObject">
<attr>
<left>10</left>
<top>3</top>
<width>father.width - 15</width>
<height>father.height - 6</height>
</attr>
</obj>
</children>
</obj>
</children>
</obj>
</children>
<eventlist>
<event name="OnMouseEnter" file="MainMenu.xml.lua" func="MainMenu_Item_OnMouseEnter"/>
<event name="OnMouseLeave" file="MainMenu.xml.lua" func="MainMenu_Item_OnMouseLeave"/>
<event name="OnLButtonDown" file="MainMenu.xml.lua" func="MainMenu_Item_OnLButtonDown"/>
<event name="OnInitControl" file="MainMenu.xml.lua" func="MainMenu_Item_OnInitControl"/>
</eventlist>
</objtemplate>
</control>
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout" version="3.2.0">
<Widget type="Window" skin="WindowC" position="20 20 170 135" layer="Info" name="Root">
<Property key="Snap" value="true"/>
<UserString key="ButtonSkin" value="Button"/>
<Widget type="ImageBox" skin="ImageBox" position="5 5 50 50" name="Icon">
<Property key="ImageResource" value="MessageBoxIcon"/>
<Property key="ImageGroup" value="Icons"/>
</Widget>
<Widget type="TextBox" skin="TextBox" position="60 5 92 50" align="Stretch" name="Text">
<Property key="TextAlign" value="Left VCenter"/>
</Widget>
<Widget type="Widget" skin="PanelEmpty" position="20 60 120 26" align="HStretch Bottom" name="ButtonPlace">
<Widget type="Button" skin="Button" position="10 0 100 26" name="ButtonTemplate"/>
</Widget>
</Widget>
</MyGUI>