Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6176 was 6176, checked in by dafrick, 14 years ago

Made NewMultiplayerMenu and NewSingleplayerMenu work. Also added hideALLGUIs functionality in InitialiseGUI

  • Property svn:eol-style set to native
File size: 5.7 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        end
87    end
88    nrOfActiveSheets = nrOfActiveSheets + 1
89    table.insert(activeSheets, filename)
90    activeSheets[nrOfActiveSheets] = filename
91    bHidePrevious[filename]=hidePrevious
92    cursorVisibility[filename] = bCursorVisible
93   
94    if hidePrevious == true then
95        for i=1,nrOfActiveSheets-1 do
96            loadedGUIs[ activeSheets[i] ]:hide()
97        end
98    end
99    currentGUI:show()
100    return currentGUI
101end
102
103function hideCursor()
104    if bShowsCursor==true then
105        bShowsCursor=false
106        cursor:hide()
107    end
108end
109
110function showCursor()
111    if bShowsCursor==false then
112        bShowsCursor=true
113        cursor:show()
114    end
115end
116
117function hideGUI(filename)
118    local currentGUI = loadedGUIs[filename]
119    if currentGUI == nil then
120        return
121    end
122    currentGUI:hide()
123    if bHidePrevious[filename] == true then
124        local i = nrOfActiveSheets-1
125        while i>0 do
126            loadedGUIs[ activeSheets[i] ]:show()
127            if bHidePrevious[filename]==true then
128                break
129            else
130                i=i-1
131            end
132        end
133    end
134    root:removeChildWindow(currentGUI.window)
135    local i=1
136    while activeSheets[i] do
137        if activeSheets[i+1] == nil then
138            if activeSheets[i-1] ~= nil then
139                if cursorVisibility[ activeSheets[i-1] ] == true then
140                    showCursor()
141                else
142                    hideCursor()
143                end
144            else
145                hideCursor()
146            end
147        end
148        if activeSheets[i] == filename then
149            table.remove( activeSheets, i )
150            nrOfActiveSheets = nrOfActiveSheets-1
151        else
152            i = i+1
153        end
154    end
155    cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table
156    bHidePrevious[filename] = nil
157    if nrOfActiveSheets == 0 then
158        orxonox.InputManager:getInstance():leaveState("guiMouseOnly")
159        hideCursor()
160    end
161end
162
163function hideAllGUIs()
164    while nrOfActiveSheets ~= 0 do
165        hideGUI(activeSheets[nrOfActiveSheets])
166    end
167end
168
169function keyESC()
170    if nrOfActiveSheets > 0 then
171        orxonox.CommandExecutor:execute("hideGUI "..activeSheets[nrOfActiveSheets])
172    else
173        showGUI("InGameMenu")
174    end
175end
176
177function setBackground(filename)
178    local newroot
179    if root ~= nil then
180        root:rename("oldRootWindow")
181    end
182    if filename ~= "" then
183        newroot = winMgr:loadWindowLayout(filename .. ".layout")
184        newroot:rename("AbsoluteRootWindow")
185        system:setGUISheet(newroot)
186    else
187        newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow")
188        newroot:setProperty("Alpha", "0.0")
189        newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))
190        system:setGUISheet(newroot)
191    end
192    if root ~= nil then
193        local child
194        while root:getChildCount()~=0 do
195            child = root:getChildAtIdx(0)
196            root:removeChildWindow(child)
197            newroot:addChildWindow(child)
198        end
199        winMgr:destroyWindow(root)
200    end
201    newroot:show()
202    root = newroot
203end
204
205function find(table, value)
206    local i=0
207    while table[i] ~= nil do
208        if table[i]==value then
209            return i
210        else
211            i=i+1
212        end
213    end
214    return nil
215end
Note: See TracBrowser for help on using the repository browser.