Changeset 5427 for data/media/gui/scripts/loadGUI.lua
- Timestamp:
- Mar 25, 2009, 11:13:58 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
data/media/gui/scripts/loadGUI.lua
r5414 r5427 3 3 local logger = CEGUI.Logger:getSingleton() 4 4 local system = CEGUI.System:getSingleton() 5 local cursor = CEGUI.MouseCursor:getSingleton() 5 6 6 7 schemeMgr:loadScheme("TaharezLookSkin.scheme") 8 -- load scheme with our own images 9 schemeMgr:loadScheme("OrxonoxGUIScheme.scheme") 10 7 11 system:setDefaultMouseCursor("TaharezLook", "MouseArrow") 8 12 system:setDefaultFont("BlueHighway-12") 9 13 14 local current = nil 15 local loadedGUIs = {} 16 local showing 17 -- we cannot directly call functions with parameters and so need this as a global variable, which sucks of course 18 filename = "" 19 datapath = "" -- points to media-folder (set after loading the script) 10 20 11 local mainmenu = winMgr:loadWindowLayout("MainMenu.layout") 12 13 local backgroundImage = CEGUI.ImagesetManager:getSingleton():createImagesetFromImageFile("GUI/Background", "main_menu_1.jpg") 14 local background = winMgr:createWindow("TaharezLook/StaticImage", "orxonox/Background") 15 background:setProperty("FrameEnabled", "set: true") 16 background:setProperty("BackgroundEnabled", "set: false") 17 background:setProperty("Image", "set: GUI/Background image:full_image") 18 19 background:addChildWindow(mainmenu) 20 21 22 function button_quit_clicked(e) 23 hideGUI() 24 orxonox.CommandExecutor:execute("exit") 21 -- function to add a reference to list of reference of loaded GUIs 22 loadedGUIs.addGUI = function (gui) 23 loadedGUIs[#loadedGUIs+1] = gui 25 24 end 26 25 27 function button_standalone_clicked(e) 28 orxonox.CommandExecutor:execute("selectGameState standalone") 29 hideGUI() 26 -- function which returns a GUI by name 27 loadedGUIs.getGUIbyName = function (str) 28 for i = 1, #loadedGUIs, 1 do 29 if str == loadedGUIs[i].filename then 30 return loadedGUIs[i] 31 end 32 end 33 return nil 30 34 end 31 35 32 function button_server_clicked(e) 33 orxonox.CommandExecutor:execute("selectGameState server") 34 hideGUI() 36 -- loads the GUI with the specified filename 37 -- be sure to set the global variable "filename" before calling this function 38 function loadGUI() 39 -- check if it already exists 40 newlyLoaded = loadedGUIs:getGUIbyName(filename) 41 if newlyLoaded == nil then 42 dofile(datapath .. "gui/scripts/" .. filename) 43 newlyLoaded = winMgr:loadWindowLayout(layoutPath) 44 newlyLoaded.filename = filename 45 loadedGUIs:addGUI(newlyLoaded) 46 -- if there has no GUI been loaded yet, set new GUI as current 47 if #loadedGUIs == 1 then 48 current = loadedGUIs[1] 49 showing = false 50 end 51 -- hide new GUI as we do not want to show it accidentially 52 newlyLoaded:hide() 53 end 54 return newlyLoaded 35 55 end 36 56 37 function button_dedicated_clicked(e) 38 orxonox.CommandExecutor:execute("selectGameState dedicated") 39 hideGUI() 57 -- shows the specified and loads it if not loaded already 58 -- be sure to set the global variable "filename" before calling this function 59 function showGUI() 60 if current == nil or current.filename ~= filename then 61 current = loadedGUIs.getGUIbyName(filename) 62 if current == nil then 63 current = loadGUI(filename) 64 end 65 system:setGUISheet(current) 66 end 67 current:show() 68 cursor:show() 69 showing = true 40 70 end 41 42 function button_client_clicked(e)43 orxonox.CommandExecutor:execute("selectGameState client")44 hideGUI()45 end46 47 showBackground = true48 49 function showMainMenu()50 if showBackground == true then51 system:setGUISheet(background)52 else53 orxonox.GUIManager:getInstance():testOutput("set new Menu")54 system:setGUISheet(mainmenu)55 end56 return 0;57 end58 59 showing = true60 71 61 72 function toggleGUI() 62 73 if showing == true then 63 mainmenu:hide() 74 current:hide() 75 cursor:hide() 64 76 showing = false 65 orxonox.GUIManager:getInstance():testOutput("hiding Menu")66 77 else 67 mainmenu:show() 78 current:show() 79 cursor:show() 68 80 showing = true 69 orxonox.GUIManager:getInstance():testOutput("showing Menu")70 81 end 82 return showing 71 83 end 72 84 73 85 function hideGUI() 74 --system:setGUISheet(nil)75 --orxonox.GUIManager:getInstance():hideGUI()86 current:hide() 87 showing = false 76 88 end
Note: See TracChangeset
for help on using the changeset viewer.