Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Changed the way windows are aliased: Instead of defining "MenuWidgets/Button", we now define "TaharezLook/Button" and then make an alias.

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