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