[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 = {} |
---|
[6024] | 16 | cursorVisibility = {} |
---|
| 17 | activeSheets = {} |
---|
| 18 | nrOfActiveSheets = 0 |
---|
| 19 | root = nil |
---|
| 20 | bShowsCursor = false |
---|
[6032] | 21 | bHidePrevious = {} |
---|
[5491] | 22 | |
---|
[6048] | 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) |
---|
[6048] | 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 | |
---|
[6032] | 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 |
---|
[6032] | 55 | function showGUI(filename, hidePrevious, bCursorVisible) |
---|
[6024] | 56 | if bCursorVisible == nil then |
---|
[6032] | 57 | bCursorVisible = true |
---|
[5491] | 58 | end |
---|
| 59 | |
---|
[6024] | 60 | if root == nil then |
---|
[6032] | 61 | setBackground("") |
---|
[6024] | 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 |
---|
[6024] | 77 | hideCursor() |
---|
[5491] | 78 | end |
---|
[6024] | 79 | |
---|
[6032] | 80 | if find( activeSheets, filename ) ~= nil then |
---|
| 81 | table.remove( activeSheets, find( activeSheets, filename ) ) |
---|
| 82 | nrOfActiveSheets = nrOfActiveSheets - 1 |
---|
| 83 | end |
---|
[6024] | 84 | nrOfActiveSheets = nrOfActiveSheets + 1 |
---|
| 85 | table.insert(activeSheets, filename) |
---|
| 86 | activeSheets[nrOfActiveSheets] = filename |
---|
[6032] | 87 | bHidePrevious[filename]=hidePrevious |
---|
| 88 | cursorVisibility[filename] = bCursorVisible |
---|
[6024] | 89 | |
---|
[6032] | 90 | if hidePrevious == true then |
---|
| 91 | for i=1,nrOfActiveSheets-1 do |
---|
| 92 | loadedGUIs[ activeSheets[i] ]:hide() |
---|
| 93 | end |
---|
| 94 | end |
---|
[6024] | 95 | currentGUI:show() |
---|
| 96 | return currentGUI |
---|
[5491] | 97 | end |
---|
| 98 | |
---|
| 99 | function hideCursor() |
---|
[6024] | 100 | if bShowsCursor==true then |
---|
| 101 | bShowsCursor=false |
---|
| 102 | cursor:hide() |
---|
| 103 | end |
---|
[5491] | 104 | end |
---|
| 105 | |
---|
| 106 | function showCursor() |
---|
[6024] | 107 | if bShowsCursor==false then |
---|
| 108 | bShowsCursor=true |
---|
| 109 | cursor:show() |
---|
| 110 | end |
---|
[5491] | 111 | end |
---|
| 112 | |
---|
| 113 | function hideGUI(filename) |
---|
[6024] | 114 | local currentGUI = loadedGUIs[filename] |
---|
| 115 | if currentGUI == nil then |
---|
| 116 | return |
---|
[5491] | 117 | end |
---|
[6024] | 118 | currentGUI:hide() |
---|
[6032] | 119 | if bHidePrevious[filename] == true then |
---|
| 120 | local i = nrOfActiveSheets-1 |
---|
| 121 | while i>0 do |
---|
| 122 | loadedGUIs[ activeSheets[i] ]:show() |
---|
| 123 | if bHidePrevious[filename]==true then |
---|
| 124 | break |
---|
| 125 | else |
---|
| 126 | i=i-1 |
---|
| 127 | end |
---|
| 128 | end |
---|
| 129 | end |
---|
[6024] | 130 | root:removeChildWindow(currentGUI.window) |
---|
[6032] | 131 | local i=1 |
---|
[6024] | 132 | while activeSheets[i] do |
---|
| 133 | if activeSheets[i+1] == nil then |
---|
| 134 | if activeSheets[i-1] ~= nil then |
---|
| 135 | if cursorVisibility[ activeSheets[i-1] ] == true then |
---|
| 136 | showCursor() |
---|
| 137 | else |
---|
| 138 | hideCursor() |
---|
| 139 | end |
---|
| 140 | else |
---|
| 141 | hideCursor() |
---|
| 142 | end |
---|
| 143 | end |
---|
| 144 | if activeSheets[i] == filename then |
---|
| 145 | table.remove( activeSheets, i ) |
---|
| 146 | nrOfActiveSheets = nrOfActiveSheets-1 |
---|
| 147 | else |
---|
| 148 | i = i+1 |
---|
| 149 | end |
---|
| 150 | end |
---|
| 151 | cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table |
---|
[6032] | 152 | bHidePrevious[filename] = nil |
---|
[5491] | 153 | end |
---|
[6032] | 154 | |
---|
[6048] | 155 | function keyESC() |
---|
| 156 | orxonox.CommandExecutor:execute("hideGUI "..activeSheets[nrOfActiveSheets]) |
---|
| 157 | end |
---|
| 158 | |
---|
[6032] | 159 | function setBackground(filename) |
---|
| 160 | local newroot |
---|
| 161 | if root ~= nil then |
---|
| 162 | root:rename("oldRootWindow") |
---|
| 163 | end |
---|
| 164 | if filename ~= "" then |
---|
| 165 | newroot = winMgr:loadWindowLayout(filename .. ".layout") |
---|
| 166 | newroot:rename("AbsoluteRootWindow") |
---|
| 167 | system:setGUISheet(newroot) |
---|
| 168 | else |
---|
| 169 | newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow") |
---|
| 170 | newroot:setProperty("Alpha", "0.0") |
---|
| 171 | newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0))) |
---|
| 172 | system:setGUISheet(newroot) |
---|
| 173 | end |
---|
| 174 | if root ~= nil then |
---|
| 175 | local child |
---|
[6148] | 176 | while root:getChildCount()~=0 do |
---|
| 177 | debug(root:getChildCount()) |
---|
| 178 | child = root:getChildAtIdx(0) |
---|
[6032] | 179 | root:removeChildWindow(child) |
---|
| 180 | newroot:addChildWindow(child) |
---|
| 181 | end |
---|
| 182 | winMgr:destroyWindow(root) |
---|
| 183 | end |
---|
| 184 | newroot:show() |
---|
| 185 | root = newroot |
---|
| 186 | end |
---|
| 187 | |
---|
| 188 | function find(table, value) |
---|
| 189 | local i=0 |
---|
| 190 | while table[i] ~= nil do |
---|
| 191 | if table[i]==value then |
---|
| 192 | return i |
---|
| 193 | else |
---|
| 194 | i=i+1 |
---|
| 195 | end |
---|
| 196 | end |
---|
| 197 | return nil |
---|
| 198 | end |
---|