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