參考了:cegui 魔獸世界 迅雷 mygui
主要問題如下:
Q1: 控件的屬性是放到xml節(jié)點(diǎn)的屬性中,還是作為子節(jié)點(diǎn)。放到屬性中方便,但是xml太長,人眼看的時(shí)候費(fèi)勁,子節(jié)點(diǎn)會好很多。
Q2: 控件之間的父子關(guān)系是直接用xml的節(jié)點(diǎn)父子關(guān)系來表達(dá),還是和魔獸世界一樣允許
parent="UIParent",這樣設(shè)置。我可能還需要“include”其他xml中定義的控件?
直接xml父子節(jié)點(diǎn):優(yōu)勢是關(guān)系簡單明了,缺陷是UI復(fù)雜以后堆積的xml文件太長,人眼也無法看明白了
魔獸世界:他們的做法可以分離每個(gè)控件出來,但是層次關(guān)系又不明朗了。
允許類似<Window></InsertControlByName name="ChirdControl" type="Type"></Window>這樣的特殊節(jié)點(diǎn),平衡兩者有優(yōu)劣勢。但是名字空間還是需要非常留意的點(diǎn)。
另外可以支持<ExportControls></Window name="ExportWnd"></ExportControls>,<InportControls></InportControl name="Import" type="Type" ImportFile="xxx.xml"><InportControls>
type屬性不必要,但是加上以后可以讓xml自校驗(yàn)?zāi)芰Ω鼜?qiáng)
解決名字沖突還是沒什么辦法。但是庫必須提供名字無關(guān)的控件消息綁定手段!允許全局重復(fù)名字的控件
<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("++ 進(jìn)入窗體:" .. 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>