Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gamestates2/data/gui/scripts/InitialiseGUI.lua @ 6595

Last change on this file since 6595 was 6595, checked in by rgrieder, 15 years ago

Merged remaining revisions from gamestate to gamestates2.

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