Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/data/gui/scripts/InitialiseGUI.lua @ 6202

Last change on this file since 6202 was 6199, checked in by scheusso, 15 years ago

hide controller overlay when in gui mode

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1local schemeMgr = CEGUI.SchemeManager:getSingleton()
2winMgr = CEGUI.WindowManager:getSingleton()
3local logger = CEGUI.Logger:getSingleton()
4local system = CEGUI.System:getSingleton()
5local cursor = CEGUI.MouseCursor:getSingleton()
6
7schemeMgr:loadScheme("TaharezLookSkin.scheme")
8-- load scheme with our own images
9schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
10
11system:setDefaultMouseCursor("TaharezLook", "MouseArrow")
12system:setDefaultFont("BlueHighway-12")
13system:setDefaultTooltip("TaharezLook/Tooltip")
14
15loadedGUIs = {}
16cursorVisibility = {}
17activeSheets = {}
18nrOfActiveSheets = 0
19root = nil
20bShowsCursor = false
21bHidePrevious = {}
22
23-- Require all tools
24require("GUITools")
25
26-- loads the GUI with the specified filename
27-- be sure to set the global variable "filename" before calling this function
28function loadGUI(filename)
29    -- check if it already exists
30    loadedGui = loadedGUIs[filename]
31    if loadedGui == nil then
32        loadedGuiNS = require(filename)
33        if loadedGuiNS == nil then
34            return
35        end
36        loadedGui = loadedGuiNS:load()
37        loadedGUIs[filename] = loadedGui
38        -- if there has no GUI been loaded yet, set new GUI as current
39        if table.getn(loadedGUIs) == 1 then
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
46end
47
48function showGUI(filename, hidePrevious, bCursorVisible, ptr)
49    gui = showGUI(filename, hidePrevious, bCursorVisible)
50    gui.overlay = ptr
51end
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
55function showGUI(filename, hidePrevious, bCursorVisible)
56    if bCursorVisible == nil then
57        bCursorVisible = true
58    end
59
60    if root == nil then
61        setBackground("")
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()
76    else
77        hideCursor()
78    end
79   
80    if find( activeSheets, filename ) ~= nil then
81        table.remove( activeSheets, find( activeSheets, filename ) )
82        nrOfActiveSheets = nrOfActiveSheets - 1
83    else
84        if nrOfActiveSheets == 0 then
85            orxonox.InputManager:getInstance():enterState("guiMouseOnly")
86            orxonox.HumanController:pauseControl()
87        end
88    end
89    nrOfActiveSheets = nrOfActiveSheets + 1
90    table.insert(activeSheets, filename)
91    activeSheets[nrOfActiveSheets] = filename
92    bHidePrevious[filename]=hidePrevious
93    cursorVisibility[filename] = bCursorVisible
94   
95    if hidePrevious == true then
96        for i=1,nrOfActiveSheets-1 do
97            loadedGUIs[ activeSheets[i] ]:hide()
98        end
99    end
100    currentGUI:show()
101    return currentGUI
102end
103
104function hideCursor()
105    if bShowsCursor==true then
106        bShowsCursor=false
107        cursor:hide()
108    end
109end
110
111function showCursor()
112    if bShowsCursor==false then
113        bShowsCursor=true
114        cursor:show()
115    end
116end
117
118function hideGUI(filename)
119    local currentGUI = loadedGUIs[filename]
120    if currentGUI == nil then
121        return
122    end
123    currentGUI:hide()
124    if bHidePrevious[filename] == true then
125        local i = nrOfActiveSheets-1
126        while i>0 do
127            loadedGUIs[ activeSheets[i] ]:show()
128            if bHidePrevious[filename]==true then
129                break
130            else
131                i=i-1
132            end
133        end
134    end
135    root:removeChildWindow(currentGUI.window)
136    local i=1
137    while activeSheets[i] do
138        if activeSheets[i+1] == nil then
139            if activeSheets[i-1] ~= nil then
140                if cursorVisibility[ activeSheets[i-1] ] == true then
141                    showCursor()
142                else
143                    hideCursor()
144                end
145            else
146                hideCursor()
147            end
148        end
149        if activeSheets[i] == filename then
150            table.remove( activeSheets, i )
151            nrOfActiveSheets = nrOfActiveSheets-1
152        else
153            i = i+1
154        end
155    end
156    cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table
157    bHidePrevious[filename] = nil
158    if nrOfActiveSheets == 0 then
159        orxonox.InputManager:getInstance():leaveState("guiMouseOnly")
160        orxonox.HumanController:resumeControl()
161        hideCursor()
162    end
163end
164
165function hideAllGUIs()
166    while nrOfActiveSheets ~= 0 do
167        hideGUI(activeSheets[nrOfActiveSheets])
168    end
169end
170
171function keyESC()
172    if nrOfActiveSheets > 0 then
173        orxonox.CommandExecutor:execute("hideGUI "..activeSheets[nrOfActiveSheets])
174    else
175        showGUI("InGameMenu")
176    end
177end
178
179function setBackground(filename)
180    local newroot
181    if root ~= nil then
182        root:rename("oldRootWindow")
183    end
184    if filename ~= "" then
185        newroot = winMgr:loadWindowLayout(filename .. ".layout")
186        newroot:rename("AbsoluteRootWindow")
187        system:setGUISheet(newroot)
188    else
189        newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow")
190        newroot:setProperty("Alpha", "0.0")
191        newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))
192        system:setGUISheet(newroot)
193    end
194    if root ~= nil then
195        local child
196        while root:getChildCount()~=0 do
197            child = root:getChildAtIdx(0)
198            root:removeChildWindow(child)
199            newroot:addChildWindow(child)
200        end
201        winMgr:destroyWindow(root)
202    end
203    newroot:show()
204    root = newroot
205end
206
207function find(table, value)
208    local i=0
209    while table[i] ~= nil do
210        if table[i]==value then
211            return i
212        else
213            i=i+1
214        end
215    end
216    return nil
217end
Note: See TracBrowser for help on using the repository browser.