[6537] | 1 | winMgr = CEGUI.WindowManager:getSingleton() |
---|
| 2 | guiMgr = orxonox.GUIManager:getInstance() |
---|
| 3 | inputMgr = orxonox.InputManager:getInstance() |
---|
| 4 | |
---|
[5491] | 5 | local schemeMgr = CEGUI.SchemeManager:getSingleton() |
---|
[6537] | 6 | local system = CEGUI.System:getSingleton() |
---|
| 7 | local cursor = CEGUI.MouseCursor:getSingleton() |
---|
[5491] | 8 | |
---|
[6566] | 9 | -- Load all required skins |
---|
[6572] | 10 | schemeMgr:loadScheme("TaharezGreenLook.scheme") |
---|
| 11 | --schemeMgr:loadScheme("TaharezLook.scheme") |
---|
[6569] | 12 | --schemeMgr:loadScheme("WindowsLook.scheme") |
---|
| 13 | --schemeMgr:loadScheme("VanillaLook.scheme") |
---|
| 14 | --schemeMgr:loadScheme("SleekSpaceLook.scheme") |
---|
[6566] | 15 | |
---|
| 16 | -- Connect skin specific window types with our own window types |
---|
| 17 | -- By loading a different file (if there is) you can change the skin |
---|
| 18 | -- of the menus or the HUD independently |
---|
[6572] | 19 | schemeMgr:loadScheme("TaharezGreenMenuWidgets.scheme") |
---|
| 20 | menuImageSet = "TaharezGreenLook" |
---|
| 21 | schemeMgr:loadScheme("TaharezGreenHUDWidgets.scheme") |
---|
| 22 | hudImageSet = "TaharezGreenLook" |
---|
[6566] | 23 | |
---|
| 24 | -- Just a remaining test hack |
---|
[5491] | 25 | schemeMgr:loadScheme("OrxonoxGUIScheme.scheme") |
---|
| 26 | |
---|
[6571] | 27 | system:setDefaultMouseCursor(menuImageSet, "MouseArrow") |
---|
[5491] | 28 | system:setDefaultFont("BlueHighway-12") |
---|
[6564] | 29 | system:setDefaultTooltip("MenuWidgets/Tooltip") |
---|
[5491] | 30 | |
---|
| 31 | loadedGUIs = {} |
---|
[6417] | 32 | cursorVisibility = {} |
---|
| 33 | activeSheets = {} |
---|
| 34 | nrOfActiveSheets = 0 |
---|
| 35 | root = nil |
---|
| 36 | bShowsCursor = false |
---|
| 37 | bHidePrevious = {} |
---|
[5491] | 38 | |
---|
[6417] | 39 | -- Require all tools |
---|
| 40 | require("GUITools") |
---|
| 41 | |
---|
[5491] | 42 | -- loads the GUI with the specified filename |
---|
| 43 | -- be sure to set the global variable "filename" before calling this function |
---|
| 44 | function loadGUI(filename) |
---|
| 45 | -- check if it already exists |
---|
| 46 | loadedGui = loadedGUIs[filename] |
---|
| 47 | if loadedGui == nil then |
---|
| 48 | loadedGuiNS = require(filename) |
---|
[6417] | 49 | if loadedGuiNS == nil then |
---|
| 50 | return |
---|
| 51 | end |
---|
[5491] | 52 | loadedGui = loadedGuiNS:load() |
---|
| 53 | loadedGUIs[filename] = loadedGui |
---|
| 54 | -- if there has no GUI been loaded yet, set new GUI as current |
---|
[5580] | 55 | if table.getn(loadedGUIs) == 1 then |
---|
[5491] | 56 | current = loadedGUIs[1] |
---|
| 57 | end |
---|
| 58 | -- hide new GUI as we do not want to show it accidentially |
---|
| 59 | loadedGui:hide() |
---|
| 60 | end |
---|
| 61 | return loadedGui |
---|
| 62 | end |
---|
| 63 | |
---|
[6417] | 64 | function showGUI(filename, hidePrevious, bCursorVisible, ptr) |
---|
| 65 | gui = showGUI(filename, hidePrevious, bCursorVisible) |
---|
[5491] | 66 | gui.overlay = ptr |
---|
| 67 | end |
---|
| 68 | |
---|
[6544] | 69 | -- shows the specified GUI sheet and loads it if not loaded already |
---|
[6417] | 70 | function showGUI(filename, hidePrevious, bCursorVisible) |
---|
| 71 | if bCursorVisible == nil then |
---|
| 72 | if nrOfActiveSheets > 0 then |
---|
| 73 | bCursorVisible = cursorVisibility[activeSheets[nrOfActiveSheets]] |
---|
| 74 | else |
---|
| 75 | bCursorVisible = true |
---|
[5491] | 76 | end |
---|
| 77 | end |
---|
| 78 | |
---|
[6417] | 79 | if root == nil then |
---|
| 80 | setBackground("") |
---|
| 81 | end |
---|
| 82 | |
---|
| 83 | local currentGUI = loadedGUIs[filename] |
---|
| 84 | if(currentGUI == nil) then |
---|
| 85 | currentGUI = loadGUI(filename) |
---|
| 86 | end |
---|
| 87 | |
---|
| 88 | if(root:isChild(currentGUI.window)) then |
---|
| 89 | root:removeChildWindow(currentGUI.window) |
---|
| 90 | end |
---|
| 91 | root:addChildWindow(currentGUI.window) |
---|
| 92 | |
---|
| 93 | if bCursorVisible then |
---|
| 94 | showCursor() |
---|
[5491] | 95 | else |
---|
[6417] | 96 | hideCursor() |
---|
[5491] | 97 | end |
---|
[6417] | 98 | |
---|
| 99 | if find( activeSheets, filename ) ~= nil then |
---|
| 100 | table.remove( activeSheets, find( activeSheets, filename ) ) |
---|
| 101 | nrOfActiveSheets = nrOfActiveSheets - 1 |
---|
| 102 | else |
---|
| 103 | if nrOfActiveSheets == 0 then |
---|
[6537] | 104 | --orxonox.InputManager:getInstance():enterState("guiMouseOnly") |
---|
[6417] | 105 | orxonox.HumanController:pauseControl() |
---|
| 106 | end |
---|
| 107 | end |
---|
[6537] | 108 | orxonox.InputManager:getInstance():enterState(currentGUI.inputState) |
---|
| 109 | |
---|
[6417] | 110 | nrOfActiveSheets = nrOfActiveSheets + 1 |
---|
| 111 | table.insert(activeSheets, filename) |
---|
| 112 | activeSheets[nrOfActiveSheets] = filename |
---|
| 113 | bHidePrevious[filename]=hidePrevious |
---|
| 114 | cursorVisibility[filename] = bCursorVisible |
---|
| 115 | |
---|
| 116 | if hidePrevious == true then |
---|
| 117 | for i=1,nrOfActiveSheets-1 do |
---|
| 118 | loadedGUIs[ activeSheets[i] ]:hide() |
---|
| 119 | end |
---|
| 120 | end |
---|
| 121 | currentGUI:show() |
---|
| 122 | return currentGUI |
---|
[5491] | 123 | end |
---|
| 124 | |
---|
| 125 | function hideCursor() |
---|
[6417] | 126 | if bShowsCursor==true then |
---|
| 127 | bShowsCursor=false |
---|
| 128 | cursor:hide() |
---|
| 129 | end |
---|
[5491] | 130 | end |
---|
| 131 | |
---|
| 132 | function showCursor() |
---|
[6417] | 133 | if bShowsCursor==false then |
---|
| 134 | bShowsCursor=true |
---|
| 135 | cursor:show() |
---|
| 136 | end |
---|
[5491] | 137 | end |
---|
| 138 | |
---|
| 139 | function hideGUI(filename) |
---|
[6417] | 140 | local currentGUI = loadedGUIs[filename] |
---|
| 141 | if currentGUI == nil then |
---|
| 142 | return |
---|
[5491] | 143 | end |
---|
[6417] | 144 | currentGUI:hide() |
---|
| 145 | if bHidePrevious[filename] == true then |
---|
| 146 | local i = nrOfActiveSheets-1 |
---|
| 147 | while i>0 do |
---|
| 148 | loadedGUIs[ activeSheets[i] ]:show() |
---|
| 149 | if bHidePrevious[filename]==true then |
---|
| 150 | break |
---|
| 151 | else |
---|
| 152 | i=i-1 |
---|
| 153 | end |
---|
| 154 | end |
---|
| 155 | end |
---|
| 156 | root:removeChildWindow(currentGUI.window) |
---|
| 157 | local i=1 |
---|
| 158 | while activeSheets[i] do |
---|
| 159 | if activeSheets[i+1] == nil then |
---|
| 160 | if activeSheets[i-1] ~= nil then |
---|
| 161 | if cursorVisibility[ activeSheets[i-1] ] == true then |
---|
| 162 | showCursor() |
---|
| 163 | else |
---|
| 164 | hideCursor() |
---|
| 165 | end |
---|
| 166 | else |
---|
| 167 | hideCursor() |
---|
| 168 | end |
---|
| 169 | end |
---|
| 170 | if activeSheets[i] == filename then |
---|
| 171 | table.remove( activeSheets, i ) |
---|
| 172 | nrOfActiveSheets = nrOfActiveSheets-1 |
---|
| 173 | else |
---|
| 174 | i = i+1 |
---|
| 175 | end |
---|
| 176 | end |
---|
| 177 | cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table |
---|
| 178 | bHidePrevious[filename] = nil |
---|
| 179 | if nrOfActiveSheets == 0 then |
---|
[6537] | 180 | --orxonox.InputManager:getInstance():leaveState("guiMouseOnly") |
---|
[6417] | 181 | orxonox.HumanController:resumeControl() |
---|
| 182 | hideCursor() |
---|
| 183 | end |
---|
[6537] | 184 | orxonox.InputManager:getInstance():leaveState(currentGUI.inputState) |
---|
[5491] | 185 | end |
---|
[6417] | 186 | |
---|
| 187 | function hideAllGUIs() |
---|
| 188 | while nrOfActiveSheets ~= 0 do |
---|
| 189 | hideGUI(activeSheets[nrOfActiveSheets]) |
---|
| 190 | end |
---|
| 191 | end |
---|
| 192 | |
---|
| 193 | function keyESC() |
---|
| 194 | if nrOfActiveSheets == 1 and activeSheets[1] == "MainMenu" then |
---|
| 195 | orxonox.execute("exit") |
---|
| 196 | elseif nrOfActiveSheets > 0 then |
---|
| 197 | orxonox.execute("hideGUI "..activeSheets[nrOfActiveSheets]) |
---|
| 198 | else |
---|
| 199 | showGUI("InGameMenu") |
---|
| 200 | end |
---|
| 201 | end |
---|
| 202 | |
---|
| 203 | function setBackground(filename) |
---|
| 204 | local newroot |
---|
| 205 | if root ~= nil then |
---|
| 206 | root:rename("oldRootWindow") |
---|
| 207 | end |
---|
| 208 | if filename ~= "" then |
---|
| 209 | newroot = winMgr:loadWindowLayout(filename .. ".layout") |
---|
| 210 | newroot:rename("AbsoluteRootWindow") |
---|
| 211 | system:setGUISheet(newroot) |
---|
| 212 | else |
---|
| 213 | newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow") |
---|
| 214 | newroot:setProperty("Alpha", "0.0") |
---|
| 215 | newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0))) |
---|
| 216 | system:setGUISheet(newroot) |
---|
| 217 | end |
---|
| 218 | if root ~= nil then |
---|
| 219 | local child |
---|
| 220 | while root:getChildCount()~=0 do |
---|
| 221 | child = root:getChildAtIdx(0) |
---|
| 222 | root:removeChildWindow(child) |
---|
| 223 | newroot:addChildWindow(child) |
---|
| 224 | end |
---|
| 225 | winMgr:destroyWindow(root) |
---|
| 226 | end |
---|
| 227 | newroot:show() |
---|
| 228 | root = newroot |
---|
| 229 | end |
---|
| 230 | |
---|
| 231 | function find(table, value) |
---|
| 232 | local i=0 |
---|
| 233 | while table[i] ~= nil do |
---|
| 234 | if table[i]==value then |
---|
| 235 | return i |
---|
| 236 | else |
---|
| 237 | i=i+1 |
---|
| 238 | end |
---|
| 239 | end |
---|
| 240 | return nil |
---|
| 241 | end |
---|
| 242 | |
---|
| 243 | function test(e) |
---|
| 244 | debug(0, "Blubb") |
---|
| 245 | end |
---|