URL: https://linuxfr.org/forums/programmationautre/posts/lua-factoriser-du-code Title: LUA : factoriser du code Authors: xabi Date: 2009年11月30日T16:40:20+01:00 Tags: Score: -4 Bonjour, Je debut en lua et je voudrais factoriser ce code : ----------------------------------------- -- Script Entry Point ----------------------------------------- local system = CEGUI.System:getSingleton() local schemeMgr = CEGUI.SchemeManager:getSingleton() local winMgr = CEGUI.WindowManager:getSingleton() --PPT local root_commande = winMgr:loadWindowLayout("ppt_dev_commande.layout") local root_1 = winMgr:loadWindowLayout("ppt_dev_1.layout") local root_2 = winMgr:loadWindowLayout("ppt_dev_2.layout") local root_3 = winMgr:loadWindowLayout("ppt_dev_3.layout") --- video = winMgr:getWindow("ModuleVideo") current_win = root_1 function hide(e) £spaces£ £/spaces£local we = CEGUI.toWindowEventArgs(e) £spaces£ £/spaces£we.window:hide() £spaces£ £/spaces£current_win = we.window end function show(e) £spaces£ £/spaces£local we = CEGUI.toWindowEventArgs(e) £spaces£ £/spaces£current_win:show() end winMgr:getWindow("PPTDEVCommande/Fond/button"):subscribeEvent("Clicked", "show") function showVideo(e) £spaces£ £/spaces£video:show() end --Masquage Video ---video:hide() --winMgr:getWindow("PPT_Win_amel_2/bouton_play"):subscribeEvent("Clicked", "showVideo") --Picking root_commande:setMousePassThroughEnabled( true) root_1:setMousePassThroughEnabled( true) root_1:subscribeEvent("CloseClicked","hide") root_2:setMousePassThroughEnabled( true) root_2:subscribeEvent("CloseClicked","hide") root_3:setMousePassThroughEnabled( true) root_3:subscribeEvent("CloseClicked","hide") CEGUI.System:getSingleton():getGUISheet():addChildWindow(root_commande) CEGUI.System:getSingleton():getGUISheet():addChildWindow(root_1) winMgr:getWindow("PPT_Win_1/bouton_next"):subscribeEvent("Clicked", "luabtnNext_1_clicked") function luabtnNext_1_clicked(e) £spaces£ £/spaces£local we = CEGUI.toWindowEventArgs(e) £spaces£ £/spaces£we.window:getParent():hide() £spaces£ £/spaces£CEGUI.System:getSingleton():getGUISheet():addChildWindow(root_2) root_2:show() end winMgr:getWindow("PPT_Win_2/bouton_next"):subscribeEvent("Clicked", "luabtnNext_2_clicked") winMgr:getWindow("PPT_Win_2/bouton_prev"):subscribeEvent("Clicked", "luabtnPrev_2_clicked") function luabtnNext_2_clicked(e) £spaces£ £/spaces£local we = CEGUI.toWindowEventArgs(e) £spaces£ £/spaces£we.window:getParent():hide() £spaces£ £/spaces£CEGUI.System:getSingleton():getGUISheet():addChildWindow(root_3) root_3:show() end function luabtnPrev_2_clicked(e) £spaces£ £/spaces£local we = CEGUI.toWindowEventArgs(e) £spaces£ £/spaces£we.window:getParent():hide() root_1:show() end -- 3 - 2 winMgr:getWindow("PPT_Win_3/bouton_next"):subscribeEvent("Clicked", "luabtnNext_3_clicked") winMgr:getWindow("PPT_Win_3/bouton_prev"):subscribeEvent("Clicked", "luabtnPrev_3_clicked") function luabtnNext_3_clicked(e) £spaces£ £/spaces£local we = CEGUI.toWindowEventArgs(e) £spaces£ £/spaces£we.window:getParent():hide() £spaces£ £/spaces£CEGUI.System:getSingleton():getGUISheet():addChildWindow(root_3) root_3:show() --4 qd y aura 4 end function luabtnPrev_3_clicked(e) £spaces£ £/spaces£local we = CEGUI.toWindowEventArgs(e) £spaces£ £/spaces£we.window:getParent():hide() root_2:show() end -- 4 -3 Bref faire une boucle avec une liste de variable correspondant à mes fenetres : root_1 root_2 etc... Vu que j'ai une 20 ene de fenetre ca serait cool... Merci