Changeset 6746 for code/trunk/data/gui/scripts/InitialiseGUI.lua
- Timestamp:
- Apr 16, 2010, 2:50:16 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/data/gui/scripts/InitialiseGUI.lua
r6711 r6746 1 local schemeMgr = CEGUI.SchemeManager:getSingleton() 2 winMgr = CEGUI.WindowManager:getSingleton()3 local logger = CEGUI.Logger:getSingleton()4 local system = CEGUI.System:getSingleton()5 local cursor = CEGUI.MouseCursor:getSingleton()1 -- Define some global shortcuts for common Managers 2 guiMgr = orxonox.GUIManager:getInstance() 3 inputMgr = orxonox.InputManager:getInstance() 4 schemeMgr = CEGUI.SchemeManager:getSingleton() 5 winMgr = CEGUI.WindowManager:getSingleton() 6 6 7 schemeMgr:loadScheme("TaharezLookSkin.scheme") 8 -- load scheme with our own images 7 -- Load all required skins 8 schemeMgr:loadScheme("TaharezGreenLook.scheme") 9 --schemeMgr:loadScheme("TaharezLook.scheme") 10 --schemeMgr:loadScheme("WindowsLook.scheme") 11 --schemeMgr:loadScheme("VanillaLook.scheme") 12 --schemeMgr:loadScheme("SleekSpaceLook.scheme") 13 14 -- Connect skin specific window types with our own window types 15 -- By loading a different file (if there is) you can change the skin 16 -- of the menus or the HUD independently 17 schemeMgr:loadScheme("TaharezGreenMenuWidgets.scheme") 18 menuImageSet = "TaharezGreenLook" 19 schemeMgr:loadScheme("TaharezGreenHUDWidgets.scheme") 20 hudImageSet = "TaharezGreenLook" 21 22 -- Just a remaining test hack 9 23 schemeMgr:loadScheme("OrxonoxGUIScheme.scheme") 10 24 11 system:setDefaultMouseCursor("TaharezLook", "MouseArrow") 25 local system = CEGUI.System:getSingleton() 26 system:setDefaultMouseCursor(menuImageSet, "MouseArrow") 12 27 system:setDefaultFont("BlueHighway-12") 13 system:setDefaultTooltip(" TaharezLook/Tooltip")28 system:setDefaultTooltip("MenuWidgets/Tooltip") 14 29 15 loadedGUIs = {} 16 cursorVisibility = {} 17 activeSheets = {} 18 nrOfActiveSheets = 0 19 root = nil 20 bShowsCursor = false 21 bHidePrevious = {} 22 23 -- Require all tools 30 -- Convenience function and additional tools 24 31 require("GUITools") 25 26 -- loads the GUI with the specified filename27 -- be sure to set the global variable "filename" before calling this function28 function loadGUI(filename)29 -- check if it already exists30 loadedGui = loadedGUIs[filename]31 if loadedGui == nil then32 loadedGuiNS = require(filename)33 if loadedGuiNS == nil then34 return35 end36 loadedGui = loadedGuiNS:load()37 loadedGUIs[filename] = loadedGui38 -- if there has no GUI been loaded yet, set new GUI as current39 if table.getn(loadedGUIs) == 1 then40 current = loadedGUIs[1]41 end42 -- hide new GUI as we do not want to show it accidentially43 loadedGui:hide()44 end45 return loadedGui46 end47 48 function showGUI(filename, hidePrevious, bCursorVisible, ptr)49 gui = showGUI(filename, hidePrevious, bCursorVisible)50 gui.overlay = ptr51 end52 53 -- shows the specified and loads it if not loaded already54 -- be sure to set the global variable "filename" before calling this function55 function showGUI(filename, hidePrevious, bCursorVisible)56 if bCursorVisible == nil then57 if nrOfActiveSheets > 0 then58 bCursorVisible = cursorVisibility[activeSheets[nrOfActiveSheets]]59 else60 bCursorVisible = true61 end62 end63 64 if root == nil then65 setBackground("")66 end67 68 local currentGUI = loadedGUIs[filename]69 if(currentGUI == nil) then70 currentGUI = loadGUI(filename)71 end72 73 if(root:isChild(currentGUI.window)) then74 root:removeChildWindow(currentGUI.window)75 end76 root:addChildWindow(currentGUI.window)77 78 if bCursorVisible then79 showCursor()80 else81 hideCursor()82 end83 84 if find( activeSheets, filename ) ~= nil then85 table.remove( activeSheets, find( activeSheets, filename ) )86 nrOfActiveSheets = nrOfActiveSheets - 187 else88 if nrOfActiveSheets == 0 then89 orxonox.InputManager:getInstance():enterState("guiMouseOnly")90 orxonox.HumanController:pauseControl()91 end92 end93 nrOfActiveSheets = nrOfActiveSheets + 194 table.insert(activeSheets, filename)95 activeSheets[nrOfActiveSheets] = filename96 bHidePrevious[filename]=hidePrevious97 cursorVisibility[filename] = bCursorVisible98 99 if hidePrevious == true then100 for i=1,nrOfActiveSheets-1 do101 loadedGUIs[ activeSheets[i] ]:hide()102 end103 end104 currentGUI:show()105 return currentGUI106 end107 108 function hideCursor()109 if bShowsCursor==true then110 bShowsCursor=false111 cursor:hide()112 end113 end114 115 function showCursor()116 if bShowsCursor==false then117 bShowsCursor=true118 cursor:show()119 end120 end121 122 function hideGUI(filename)123 local currentGUI = loadedGUIs[filename]124 if currentGUI == nil then125 return126 end127 currentGUI:hide()128 if bHidePrevious[filename] == true then129 local i = nrOfActiveSheets-1130 while i>0 do131 loadedGUIs[ activeSheets[i] ]:show()132 if bHidePrevious[filename]==true then133 break134 else135 i=i-1136 end137 end138 end139 root:removeChildWindow(currentGUI.window)140 local i=1141 while activeSheets[i] do142 if activeSheets[i+1] == nil then143 if activeSheets[i-1] ~= nil then144 if cursorVisibility[ activeSheets[i-1] ] == true then145 showCursor()146 else147 hideCursor()148 end149 else150 hideCursor()151 end152 end153 if activeSheets[i] == filename then154 table.remove( activeSheets, i )155 nrOfActiveSheets = nrOfActiveSheets-1156 else157 i = i+1158 end159 end160 cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table161 bHidePrevious[filename] = nil162 if nrOfActiveSheets == 0 then163 orxonox.InputManager:getInstance():leaveState("guiMouseOnly")164 orxonox.HumanController:resumeControl()165 hideCursor()166 end167 end168 169 function hideAllGUIs()170 while nrOfActiveSheets ~= 0 do171 hideGUI(activeSheets[nrOfActiveSheets])172 end173 end174 175 function keyESC()176 if nrOfActiveSheets == 1 and activeSheets[1] == "MainMenu" then177 orxonox.execute("exit")178 elseif nrOfActiveSheets > 0 then179 orxonox.execute("hideGUI "..activeSheets[nrOfActiveSheets])180 else181 showGUI("InGameMenu")182 end183 end184 185 function setBackground(filename)186 local newroot187 if root ~= nil then188 root:rename("oldRootWindow")189 end190 if filename ~= "" then191 newroot = winMgr:loadWindowLayout(filename .. ".layout")192 newroot:rename("AbsoluteRootWindow")193 system:setGUISheet(newroot)194 else195 newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow")196 newroot:setProperty("Alpha", "0.0")197 newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))198 system:setGUISheet(newroot)199 end200 if root ~= nil then201 local child202 while root:getChildCount()~=0 do203 child = root:getChildAtIdx(0)204 root:removeChildWindow(child)205 newroot:addChildWindow(child)206 end207 winMgr:destroyWindow(root)208 end209 newroot:show()210 root = newroot211 end212 213 function find(table, value)214 local i=0215 while table[i] ~= nil do216 if table[i]==value then217 return i218 else219 i=i+1220 end221 end222 return nil223 end224 225 --TODO: Needed?226 function test(e)227 debug(0, "Blubb")228 end
Note: See TracChangeset
for help on using the changeset viewer.