Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Completed skin abstraction for Taharez, Windows, Vanilla and SleeSpace Looks.
Unfortunately only Taharez and Windows work because of missing properties in the looknfeel files of the other two looks.
Maybe we can fix this ourselves some time.

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