Changeset 5428
- Timestamp:
- Mar 25, 2009, 3:17:07 PM (16 years ago)
- Location:
- data/media/gui/scripts
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
data/media/gui/scripts/loadGUI.lua
r5427 r5428 3 3 local logger = CEGUI.Logger:getSingleton() 4 4 local system = CEGUI.System:getSingleton() 5 local cursor = CEGUI.MouseCursor:getSingleton()6 5 7 6 schemeMgr:loadScheme("TaharezLookSkin.scheme") 8 -- load scheme with our own images9 schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")10 11 7 system:setDefaultMouseCursor("TaharezLook", "MouseArrow") 12 8 system:setDefaultFont("BlueHighway-12") 13 9 14 local current = nil15 local loadedGUIs = {}16 local showing17 -- we cannot directly call functions with parameters and so need this as a global variable, which sucks of course18 filename = ""19 datapath = "" -- points to media-folder (set after loading the script)20 10 21 -- function to add a reference to list of reference of loaded GUIs 22 loadedGUIs.addGUI = function (gui) 23 loadedGUIs[#loadedGUIs+1] = gui 11 local rootSheet = winMgr:createWindow("DefaultGUISheet", "orxonox/Sheet") 12 13 local leftOffset = 0.11 14 local topOffset = 0.3 15 local distance = 0.076 16 local index = 0 17 18 local standalone = winMgr:createWindow("TaharezLook/Button", "orxonox/StandaloneButton") 19 standalone:setText("Standalone") 20 standalone:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0))) 21 standalone:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0))) 22 standalone:subscribeEvent("Clicked","button_standalone_clicked") 23 index = index + 1 24 25 local dedicated = winMgr:createWindow("TaharezLook/Button", "orxonox/DedicatedButton") 26 dedicated:setText("Dedicated") 27 dedicated:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0))) 28 dedicated:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0))) 29 dedicated:subscribeEvent("Clicked","button_dedicated_clicked") 30 index = index + 1 31 32 local server = winMgr:createWindow("TaharezLook/Button", "orxonox/ServerButton") 33 server:setText("Server") 34 server:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0))) 35 server:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0))) 36 server:subscribeEvent("Clicked","button_server_clicked") 37 index = index + 1 38 39 local client = winMgr:createWindow("TaharezLook/Button", "orxonox/ClientButton") 40 client:setText("Client") 41 client:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0))) 42 client:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0))) 43 client:subscribeEvent("Clicked","button_client_clicked") 44 index = index + 1 45 46 local quit = winMgr:createWindow("TaharezLook/Button", "orxonox/QuitButton") 47 quit:setText("Quit") 48 quit:setSize(CEGUI.UVector2(CEGUI.UDim(0.15, 0), CEGUI.UDim(0.05, 0))) 49 quit:setPosition(CEGUI.UVector2(CEGUI.UDim(leftOffset, 0), CEGUI.UDim(topOffset + index * distance, 0))) 50 quit:subscribeEvent("Clicked","button_quit_clicked") 51 index = index + 1 52 53 local backgroundImage = CEGUI.ImagesetManager:getSingleton():createImagesetFromImageFile("GUI/Background", "main_menu_1.jpg") 54 local background = winMgr:createWindow("TaharezLook/StaticImage", "orxonox/Background") 55 background:setProperty("FrameEnabled", "set: true") 56 background:setProperty("BackgroundEnabled", "set: false") 57 background:setProperty("Image", "set: GUI/Background image:full_image") 58 59 rootSheet:addChildWindow(quit) 60 rootSheet:addChildWindow(standalone) 61 rootSheet:addChildWindow(server) 62 rootSheet:addChildWindow(dedicated) 63 rootSheet:addChildWindow(client) 64 background:addChildWindow(rootSheet) 65 66 67 function button_quit_clicked(e) 68 hideGUI() 69 orxonox.CommandExecutor:execute("exit") 24 70 end 25 71 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 72 function button_standalone_clicked(e) 73 orxonox.CommandExecutor:execute("selectGameState standalone") 74 hideGUI() 34 75 end 35 76 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 77 function button_server_clicked(e) 78 orxonox.CommandExecutor:execute("selectGameState server") 79 hideGUI() 55 80 end 56 81 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 82 function button_dedicated_clicked(e) 83 orxonox.CommandExecutor:execute("selectGameState dedicated") 84 hideGUI() 70 85 end 71 86 72 function toggleGUI() 73 if showing == true then 74 current:hide() 75 cursor:hide() 76 showing = false 77 else 78 current:show() 79 cursor:show() 80 showing = true 81 end 82 return showing 87 function button_client_clicked(e) 88 orxonox.CommandExecutor:execute("selectGameState client") 89 hideGUI() 90 end 91 92 showBackground = false 93 94 function showMainMenu() 95 if showBackground == true then 96 system:setGUISheet(background) 97 else 98 system:setGUISheet(rootSheet) 99 end 100 return 0; 83 101 end 84 102 85 103 function hideGUI() 86 current:hide()87 showing = false104 system:setGUISheet(nil) 105 orxonox.GUIManager:getInstance():hideGUI() 88 106 end
Note: See TracChangeset
for help on using the changeset viewer.