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