Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gamestate/data/gui/scripts/InitialiseGUI.lua @ 6544

Last change on this file since 6544 was 6544, checked in by rgrieder, 14 years ago

Removed loads of CEGUI related files that we really don't need. Most of it was just copied from the CEGUI data folder for the demo applications.

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