基於BOLT的仿迅雷加速器界面開發(二)

控件清單

<xlue author='Thunder Corporation'  copyright='(C) Thunder Corporation.'  name='BoltNameTable' >
	<nametable class='BaseUI.ScrollBar.ScrollPosAni'  id='BaseUI.ScrollBar.ScrollPosAni.Template'  path='layout\ScrollBar.xml'  type='AnimationTemplate'/>
	<nametable class=''  id='BaseUI.VScrollBar'  path='layout\ScrollBar.xml'  type='ObjectTemplate'/>
	
	<nametable class='SpeedUpjiedian_Suc.bottom'  id='SpeedUpjiedian_Suc.bottom'  path='layout\SpeedUpResult.xml'  type='control'/>
	
	<nametable class=''  id='Login.Menu'  path='layout\MenuPanel_Login.xml'  type='ObjectTreeTemplate'/>
	<nametable class='MenuHostWnd'  id='Login.Menu.Wnd'  path='layout\MenuPanel_Login.xml'  type='HostWndTemplate'/>
	
	<nametable class='FrameHostWnd'  id='FeedBackError.Wnd'  path='layout\FeedBackWndError.xml'  type='HostWndTemplate'/>
	<nametable class='ObjectTreeTemplate'  id='FeedBackError.Manager'  path='layout\FeedBackWndError.xml'  type='ObjectTreeTemplate'/>
	<nametable class='System.button'  id='System.button'  path='layout\SystemButton.xml'  type='control'/>
	<nametable class='Close.button'  id='Close.button'  path='layout\CloseButton.xml'  type='control'/>
	<nametable class='System.RichEdit'  id='System.RichEdit'  path='layout\RichEdit.xml'  type='control'/>


	<nametable class='Thunder.System.ButtonEx.Ctrl'  id='Thunder.System.ButtonEx.Ctrl'  path='layout\SystemButtonEx.xml'  type='control'/>
	<nametable class='Thunder.System.ItemEx'  id='Thunder.System.ItemEx'  path='layout\SystemButtonEx.xml'  type='control'/>

	<nametable class='Game.button'  id='Game.button'  path='layout\GameButton.xml'  type='control'/>
	<nametable class='Vip.button'  id='Vip.button'  path='layout\VipButton.xml'  type='control'/>
	<nametable class='Help.button'  id='Help.button'  path='layout\HelpButton.xml'  type='control'/>
	<nametable class='Tool.button'  id='Tool.button'  path='layout\ToolButton.xml'  type='control'/>
	<nametable class='Menu.FeedBack'  id='Menu.FeedBack'  path='layout\FeedBack.xml'  type='control'/>
	<nametable class='System.Menu'  id='System.Menu'  path='layout\Menu.xml'  type='control'/>
	<nametable class='System.Skin'  id='System.Skin'  path='layout\Skin.xml'  type='control'/>
</xlue>

目錄清單(部分)




素材



界面程序主窗口文件(MainWnd.xml,MainWnd.lua)

XML

<xlue>
	<objtreetemplate  id="XL.MainObjTree" class="ObjectTreeTemplate">
		<attr>
			<left>-200</left>
			<top>-200</top>
			<width>2000</width>
			<height>2000</height>
		</attr>
		
		<obj id="app.bkg" class="LayoutObject">
			<attr>
				<left>0</left>
				<top>0</top>
				<width>father.width</width>
				<height>father.height</height>
			</attr>
			<children>				

			<obj id="bkg" class="ImageObject">
				<attr>
				<left>0</left>
				<top>0</top>
				<width>father.width</width>
				<height>father.height</height>
				<image>bkg</image>
				</attr>
			<children>
				<obj id="caption" class="CaptionObject">
					<attr>
						<width>father.width</width>
						<height>father.height</height>
						<zorder>-1000</zorder>
					</attr>
				</obj>
				
				<obj id="mainwnd.body" class="LayoutObject">
					<attr>
						<left>8</left>
						<top>8</top>
						<width>father.width-16</width>
						<height>father.height-16</height>
					</attr>
					<children>
						<obj id="logo" class="ImageObject">
							<attr>
							<left>540</left>
							<top>20</top>
							<width>197</width>
							<height>37</height>
							<image>logo</image>
							</attr>
						</obj>
						<obj id="menu.feedback" class="Menu.FeedBack">
							<attr>
							<left>father.width - 144</left>
							<top>-8</top>
							<width>28</width>
							<height>31</height>
							</attr>
						<eventlist>
							<event name="OnClick" file="MainWnd.lua" func="CreatFeedBackManager" />
						</eventlist>
						</obj>
						<obj id="system.menu" class="System.Menu">
							<attr>
							<left>father.width - 88</left>
							<top>-8</top>
							<width>28</width>
							<height>31</height>
							</attr>
						<eventlist>
							<event name="OnClick" file="MainWnd.lua" func="CreatMenuManager" />
						</eventlist>
						</obj>
						<obj id="system.skin" class="System.Skin">
							<attr>
							<left>father.width - 116</left>
							<top>-8</top>
							<width>28</width>
							<height>31</height>
							</attr>
						</obj>
						<obj id="Button.Layout" class="LayoutObject">
							<attr>
							</attr>
						<children>
 						<obj id="game.button" class="Game.button">
							<attr>
							<left>0</left>
							<top>0</top>
							<width>70</width>
							<height>80</height>
							</attr>
						<eventlist>
							<event name="OnClick" file="MainWnd.lua" func="OnActiveTabChanged" />
						</eventlist>
						</obj> 
						<obj id="vip.button" class="Vip.button">
							<attr>
							<left>90</left>
							<top>0</top>
							<width>70</width>
							<height>80</height>
							</attr>
						<eventlist>
							<event name="OnClick" file="MainWnd.lua" func="OnActiveTabChanged" />
						</eventlist>
						</obj> 
						<obj id="help.button" class="Help.button">
							<attr>
							<left>180</left>
							<top>0</top>
							<width>70</width>
							<height>80</height>
							</attr>
						<eventlist>
							<event name="OnClick" file="MainWnd.lua" func="OnActiveTabChanged" />
						</eventlist>
						</obj> 
						<obj id="tool.button" class="Tool.button">
							<attr>
							<left>270</left>
							<top>0</top>
							<width>70</width>
							<height>80</height>
							</attr>
						<eventlist>
							<event name="OnClick" file="MainWnd.lua" func="OnActiveTabChanged" />
						</eventlist>
						</obj> 
						</children>
						</obj>
		
						<obj id="MainPanel" class="Demo.MainPanel">
							<attr>
								<left>-15</left>
								<top>-98</top>
								<width>father.width+30</width>
								<height>father.height+25</height>
							</attr>
						</obj>
						<obj id="vip.MainPanel" class="Vip.MainPanel">
							<attr>
								<left>-15</left>
								<top>-98</top>
								<width>father.width+30</width>
								<height>father.height+25</height>
							</attr>
						</obj>
						<obj id="help.MainPanel" class="Help.MainPanel">
							<attr>
								<left>-15</left>
								<top>-98</top>
								<width>father.width+30</width>
								<height>father.height+25</height>
							</attr>
						</obj>
 						<obj id="tool.MainPanel" class="Tool.MainPanel">
							<attr>
								<left>-15</left>
								<top>-98</top>
								<width>father.width+30</width>
								<height>father.height+25</height>
							</attr>
						</obj> 
						
						<obj id="mainwnd.sysbtn" class="Thunder.System.ButtonEx.Ctrl" >
							<attr>
								<left>father.width - 60</left>
								<top>-8</top>
								<width>90</width>
								<height>20</height>
								<zorder>330</zorder>		
								<ItemWidthIsSame>false</ItemWidthIsSame>
							</attr>
							<eventlist>
								<event name="OnClose" file="MainWnd.lua" func="OnClose" />
								<event name="OnInitControl" file="MainWnd.lua" func="OnSysBtnInitControl" />
								<event name="OnMinisize" file="MainWnd.lua" func="OnMinisize" />
							</eventlist>
						</obj>	
					</children>
				</obj>
				</children>
				</obj>
			</children>		
		<eventlist>
		<!--定義事件響應時,如果方法被定義在同名的.xml.lua中同時方法名爲事件名時,可以省略file 及 func屬性,會損失加載效率, 不推薦-->
			<event name="OnInitControl" file="MainWnd.lua" func="OnInitControl" />
		</eventlist>			
		</obj>	
	</objtreetemplate>

	<hostwndtemplate id="XL.MainWnd" class="FrameHostWnd" >
		<attr> 
			<mainwnd>1</mainwnd>
			<title>Bolt</title>
			<layered>1</layered>
			<left>200</left> 
			<top>100</top>
			<!--注意這是容器窗口的大小,設置的要合理-->
			<width>760</width>
			<height>500</height>
			<cacheleft>0</cacheleft> 
			<cachetop>0</cachetop>

			<cachewidth>1000</cachewidth>
			<cacheheight>720</cacheheight>
			<center>1</center>
			<visible>1</visible>
			<enable>1</enable>
			<active>1</active>
			<maxbox>0</maxbox>
			<minbox>0</minbox>
			<minwidth>100</minwidth>
			<minheight>72</minheight>
			<maxwidth>1000</maxwidth>
			<maxheight>720</maxheight>
			<appwindow>1</appwindow>
			<topmost>1</topmost>
			<fps>30</fps>
		</attr>
		<eventlist>
			<event name="OnSize" file="MainWnd.lua" func="OnSize"/>
		</eventlist> 		
	</hostwndtemplate>	
</xlue>

LUA


function OnSize(self, sizetype, width, height)

	local objectTree = self:GetBindUIObjectTree()
	local rootObject = objectTree:GetRootObject()
	rootObject:SetObjPos(0, 0, width, height)

end

function OnClose(self)
	
	local hostwndManager = XLGetObject("Xunlei.UIEngine.HostWndManager")
	local hostwnd = hostwndManager:GetHostWnd("Wizard.MainWnd.Instance")
	
	hostwndManager:RemoveHostWnd("Wizard.MainWnd.Instance")
	
	local objtreeManager = XLGetObject("Xunlei.UIEngine.TreeManager")	
	objtreeManager:DestroyTree("Wizard.MainObjTree.Instance")

	local myClassFactory = XLGetObject("HelloBolt.MyClass.Factory")
	local myClass = myClassFactory:CreateInstance()
	myClass:DeletIcon()
	os.exit(0)
	--local app = XLGetObject("Wizard.App")
	--app:Quit(0)
end

function OnSysBtnInitControl(self)
	local hostwndManager = XLGetObject("Xunlei.UIEngine.HostWndManager")
	local hostwnd = hostwndManager:GetHostWnd("XL.MainWnd.Instance")
	local state = hostwnd:GetWindowState()
end

function OnMinisize(self)
	local hostwndManager = XLGetObject("Xunlei.UIEngine.HostWndManager")
	local hostwnd = hostwndManager:GetHostWnd("XL.MainWnd.Instance")
	hostwnd:Min() 
	--hostwnd:SetVisible(false)
	
end



function GetScreenPos(menuRoot, x, y)
	local left,top,right,bottom = menuRoot:GetObjPos()
	
	local width = right - left
	local height = bottom - top
	
	local menuTree = menuRoot:GetOwner()
	local menuHostWnd = menuTree:GetBindHostWnd()
	
	local sleft, stop, sright, sbottom = menuHostWnd:GetMonitorRect(x, y)
	if x + width > sright then
		x = x - width
	end
	
	if y + height > sbottom then
		y = y - height
	end
	
	return x, y, width, height
end	
function OnMainWndRButtonUp(self, x, y)
		
	local templateMananger = XLGetObject("Xunlei.UIEngine.TemplateManager")				
	local menuTreeTemplate = templateMananger:GetTemplate("Wizard.Menu","ObjectTreeTemplate")
	local menuTree = menuTreeTemplate:CreateInstance("Wizard.Menu.Instance")
	
	local hostwndManager = XLGetObject("Xunlei.UIEngine.HostWndManager")
	local parent = hostwndManager:GetHostWnd("Wizard.MainWnd.Instance")
	local parentHandle = parent:GetWndHandle()

	local menuHostWndTemplate = templateMananger:GetTemplate("Wizard.Menu", "HostWndTemplate")
	local menuHostWnd = menuHostWndTemplate:CreateInstance("Wizard.Menu.Instance")
	
	menuHostWnd:BindUIObjectTree(menuTree)
	local menuContext = menuTree:GetUIObject("menu.root")
	
	x, y = parent:ClientPtToScreenPt(x,y)
	local left, top, width, height = GetScreenPos(menuContext, x, y)
	
	menuHostWnd:TrackPopupMenu(parentHandle, left, top, width, height)
	
	local objtreeManager = XLGetObject("Xunlei.UIEngine.TreeManager")	
	objtreeManager:DestroyTree("Wizard.Menu.Instance")
	hostwndManager:RemoveHostWnd("Wizard.Menu.Instance")
end

function OnActiveTabChanged(self)
--XLMessageBox("sadfasf")
	--XLMessageBox(self:GetClass())
	local ownerTree = self:GetOwner()
	local buttonLayout=ownerTree:GetUIObject("Button.Layout")
	local mainPanel = ownerTree:GetUIObject("MainPanel")
	local vipPanel = ownerTree:GetUIObject("vip.MainPanel")
	local helpPanel = ownerTree:GetUIObject("help.MainPanel")
	local toolPanel = ownerTree:GetUIObject("tool.MainPanel")

	mainPanel:SetVisible(false)
    mainPanel:SetChildrenVisible(false)
	
	vipPanel:SetVisible(false)
    vipPanel:SetChildrenVisible(false)
    
    helpPanel:SetVisible(false)
    helpPanel:SetChildrenVisible(false)
    
    toolPanel:SetVisible(false)
    toolPanel:SetChildrenVisible(false)
       
	local vButton=ownerTree:GetUIObject("vip.button")
	local hButton=ownerTree:GetUIObject("help.button")
	local tButton=ownerTree:GetUIObject("tool.button")
	local gButton=ownerTree:GetUIObject("game.button")
	if self:GetClass() =="Game.button" then
		mainPanel:SetVisible(true)
		mainPanel:SetChildrenVisible(true)
		vButton:SetState(0)
		hButton:SetState(0)
		tButton:SetState(0)
		vButton:SetOldState(0)
		hButton:SetOldState(0)
		tButton:SetOldState(0)
	elseif self:GetClass() == "Vip.button" then	
		vipPanel:SetVisible(true)
		vipPanel:SetChildrenVisible(true)
		gButton:SetState(0)
		hButton:SetState(0)
		tButton:SetState(0)
		gButton:SetOldState(0)
		hButton:SetOldState(0)
		tButton:SetOldState(0)
	elseif self:GetClass() == "Help.button" then
		helpPanel:SetVisible(true)
		helpPanel:SetChildrenVisible(true)
		vButton:SetState(0)
		gButton:SetState(0)
		tButton:SetState(0)
		vButton:SetOldState(0)
		gButton:SetOldState(0)
		tButton:SetOldState(0)
	elseif self:GetClass() == "Tool.button" then
		toolPanel:SetVisible(true)
		toolPanel:SetChildrenVisible(true)
		vButton:SetState(0)
		hButton:SetState(0)
		gButton:SetState(0)
		vButton:SetOldState(0)
		hButton:SetOldState(0)
		gButton:SetOldState(0)
	end
end
function OnInitControl(self)

end
function CreatFeedBackManager(self)
	--實例化skin對象樹
	local templateMananger = XLGetObject("Xunlei.UIEngine.TemplateManager")				
	local feedbackTreeTemplate = templateMananger:GetTemplate("FeedBack.Manager","ObjectTreeTemplate")
	local feedbackTree = feedbackTreeTemplate:CreateInstance("FeedBack.Manager.Instance")
	
	local hostwndManager = XLGetObject("Xunlei.UIEngine.HostWndManager")
	local parent = hostwndManager:GetHostWnd("XL.MainWnd.Instance")
	local parentHandle = parent:GetWndHandle()

	--實例化skin窗口
	local feedbackHostWndTemplate = templateMananger:GetTemplate("FeedBack.Wnd", "HostWndTemplate")
	local feedbackHostWnd = feedbackHostWndTemplate:CreateInstance("FeedBack.Wnd.Instance")
	--將skin對象樹裝在入窗口實例
	feedbackHostWnd:BindUIObjectTree(feedbackTree)
	feedbackHostWnd:Create()
end
--menuHostWnd=nil
isVisible=true
function CreatMenuManager(self)

	--實例化對象樹
	local templateMananger = XLGetObject("Xunlei.UIEngine.TemplateManager")				
	local menuTreeTemplate = templateMananger:GetTemplate("XL.Menu","ObjectTreeTemplate")
	local menuTree = menuTreeTemplate:CreateInstance("XL.Menu.Instance")
	local hostwndManager = XLGetObject("Xunlei.UIEngine.HostWndManager")
	local parent = hostwndManager:GetHostWnd("XL.MainWnd.Instance")
	local parentHandle = parent:GetWndHandle()
	--實例化skin窗口
	local menuHostWndTemplate = templateMananger:GetTemplate("XL.Menu.Wnd", "HostWndTemplate")
	local menuHostWnd = menuHostWndTemplate:CreateInstance("XL.Menu.Wnd.Instance")
	--將skin對象樹裝在入窗口實例
	menuHostWnd:BindUIObjectTree(menuTree)
	
	local menuContext = menuTree:GetUIObject("menu.root")
	x, y = parent:ClientPtToScreenPt(x,y)
	local left,top,right,bottom = menuContext:GetObjPos()
	--local left, top, width, height = GetScreenPos(menuContext, x, y)
	--XLMessageBox(x.." "..y.." "..right.." "..bottom)
	menuHostWnd:TrackPopupMenu(parentHandle, x+670, y+40, right, bottom)
	--menuHostWnd:TrackPopupMenu(parentHandle, left, top, width, height)
	local objtreeManager = XLGetObject("Xunlei.UIEngine.TreeManager")	
	objtreeManager:DestroyTree("XL.Menu.Instance")
	hostwndManager:RemoveHostWnd("XL.Menu.Wnd.Instance")
	x=0
	y=0
end



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章