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