[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 |
---|
| 57 | bCursorVisible = true |
---|
[5491] | 58 | end |
---|
| 59 | |
---|
[6150] | 60 | if root == nil then |
---|
| 61 | setBackground("") |
---|
| 62 | end |
---|
| 63 | |
---|
| 64 | local currentGUI = loadedGUIs[filename] |
---|
| 65 | if(currentGUI == nil) then |
---|
| 66 | currentGUI = loadGUI(filename) |
---|
| 67 | end |
---|
| 68 | |
---|
| 69 | if(root:isChild(currentGUI.window)) then |
---|
| 70 | root:removeChildWindow(currentGUI.window) |
---|
| 71 | end |
---|
| 72 | root:addChildWindow(currentGUI.window) |
---|
| 73 | |
---|
| 74 | if bCursorVisible then |
---|
| 75 | showCursor() |
---|
[5491] | 76 | else |
---|
[6150] | 77 | hideCursor() |
---|
[5491] | 78 | end |
---|
[6150] | 79 | |
---|
| 80 | if find( activeSheets, filename ) ~= nil then |
---|
| 81 | table.remove( activeSheets, find( activeSheets, filename ) ) |
---|
| 82 | nrOfActiveSheets = nrOfActiveSheets - 1 |
---|
| 83 | else |
---|
| 84 | if nrOfActiveSheets == 0 then |
---|
| 85 | orxonox.InputManager:getInstance():enterState("guiMouseOnly") |
---|
| 86 | end |
---|
| 87 | end |
---|
| 88 | nrOfActiveSheets = nrOfActiveSheets + 1 |
---|
| 89 | table.insert(activeSheets, filename) |
---|
| 90 | activeSheets[nrOfActiveSheets] = filename |
---|
| 91 | bHidePrevious[filename]=hidePrevious |
---|
| 92 | cursorVisibility[filename] = bCursorVisible |
---|
| 93 | |
---|
| 94 | if hidePrevious == true then |
---|
| 95 | for i=1,nrOfActiveSheets-1 do |
---|
| 96 | loadedGUIs[ activeSheets[i] ]:hide() |
---|
| 97 | end |
---|
| 98 | end |
---|
| 99 | currentGUI:show() |
---|
| 100 | return currentGUI |
---|
[5491] | 101 | end |
---|
| 102 | |
---|
| 103 | function hideCursor() |
---|
[6150] | 104 | if bShowsCursor==true then |
---|
| 105 | bShowsCursor=false |
---|
| 106 | cursor:hide() |
---|
| 107 | end |
---|
[5491] | 108 | end |
---|
| 109 | |
---|
| 110 | function showCursor() |
---|
[6150] | 111 | if bShowsCursor==false then |
---|
| 112 | bShowsCursor=true |
---|
| 113 | cursor:show() |
---|
| 114 | end |
---|
[5491] | 115 | end |
---|
| 116 | |
---|
| 117 | function hideGUI(filename) |
---|
[6150] | 118 | local currentGUI = loadedGUIs[filename] |
---|
| 119 | if currentGUI == nil then |
---|
| 120 | return |
---|
[5491] | 121 | end |
---|
[6150] | 122 | currentGUI:hide() |
---|
| 123 | if bHidePrevious[filename] == true then |
---|
| 124 | local i = nrOfActiveSheets-1 |
---|
| 125 | while i>0 do |
---|
| 126 | loadedGUIs[ activeSheets[i] ]:show() |
---|
| 127 | if bHidePrevious[filename]==true then |
---|
| 128 | break |
---|
| 129 | else |
---|
| 130 | i=i-1 |
---|
| 131 | end |
---|
| 132 | end |
---|
| 133 | end |
---|
| 134 | root:removeChildWindow(currentGUI.window) |
---|
| 135 | local i=1 |
---|
| 136 | while activeSheets[i] do |
---|
| 137 | if activeSheets[i+1] == nil then |
---|
| 138 | if activeSheets[i-1] ~= nil then |
---|
| 139 | if cursorVisibility[ activeSheets[i-1] ] == true then |
---|
| 140 | showCursor() |
---|
| 141 | else |
---|
| 142 | hideCursor() |
---|
| 143 | end |
---|
| 144 | else |
---|
| 145 | hideCursor() |
---|
| 146 | end |
---|
| 147 | end |
---|
| 148 | if activeSheets[i] == filename then |
---|
| 149 | table.remove( activeSheets, i ) |
---|
| 150 | nrOfActiveSheets = nrOfActiveSheets-1 |
---|
| 151 | else |
---|
| 152 | i = i+1 |
---|
| 153 | end |
---|
| 154 | end |
---|
| 155 | cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table |
---|
| 156 | bHidePrevious[filename] = nil |
---|
| 157 | if nrOfActiveSheets == 0 then |
---|
| 158 | orxonox.InputManager:getInstance():leaveState("guiMouseOnly") |
---|
| 159 | hideCursor() |
---|
| 160 | end |
---|
[5491] | 161 | end |
---|
[6150] | 162 | |
---|
[6176] | 163 | function hideAllGUIs() |
---|
| 164 | while nrOfActiveSheets ~= 0 do |
---|
| 165 | hideGUI(activeSheets[nrOfActiveSheets]) |
---|
| 166 | end |
---|
| 167 | end |
---|
| 168 | |
---|
[6150] | 169 | function keyESC() |
---|
| 170 | if nrOfActiveSheets > 0 then |
---|
| 171 | orxonox.CommandExecutor:execute("hideGUI "..activeSheets[nrOfActiveSheets]) |
---|
| 172 | else |
---|
| 173 | showGUI("InGameMenu") |
---|
| 174 | end |
---|
| 175 | end |
---|
| 176 | |
---|
| 177 | function setBackground(filename) |
---|
| 178 | local newroot |
---|
| 179 | if root ~= nil then |
---|
| 180 | root:rename("oldRootWindow") |
---|
| 181 | end |
---|
| 182 | if filename ~= "" then |
---|
| 183 | newroot = winMgr:loadWindowLayout(filename .. ".layout") |
---|
| 184 | newroot:rename("AbsoluteRootWindow") |
---|
| 185 | system:setGUISheet(newroot) |
---|
| 186 | else |
---|
| 187 | newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow") |
---|
| 188 | newroot:setProperty("Alpha", "0.0") |
---|
| 189 | newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0))) |
---|
| 190 | system:setGUISheet(newroot) |
---|
| 191 | end |
---|
| 192 | if root ~= nil then |
---|
| 193 | local child |
---|
| 194 | while root:getChildCount()~=0 do |
---|
| 195 | child = root:getChildAtIdx(0) |
---|
| 196 | root:removeChildWindow(child) |
---|
| 197 | newroot:addChildWindow(child) |
---|
| 198 | end |
---|
| 199 | winMgr:destroyWindow(root) |
---|
| 200 | end |
---|
| 201 | newroot:show() |
---|
| 202 | root = newroot |
---|
| 203 | end |
---|
| 204 | |
---|
| 205 | function find(table, value) |
---|
| 206 | local i=0 |
---|
| 207 | while table[i] ~= nil do |
---|
| 208 | if table[i]==value then |
---|
| 209 | return i |
---|
| 210 | else |
---|
| 211 | i=i+1 |
---|
| 212 | end |
---|
| 213 | end |
---|
| 214 | return nil |
---|
| 215 | end |
---|