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