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, 16 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
RevLine 
[6537]1winMgr   = CEGUI.WindowManager:getSingleton()
2guiMgr   = orxonox.GUIManager:getInstance()
3inputMgr = orxonox.InputManager:getInstance()
4
[5491]5local schemeMgr = CEGUI.SchemeManager:getSingleton()
[6537]6local system    = CEGUI.System:getSingleton()
7local cursor    = CEGUI.MouseCursor:getSingleton()
[5491]8
[6566]9-- Load all required skins
10schemeMgr:loadScheme("TaharezLook.scheme")
[6569]11--schemeMgr:loadScheme("WindowsLook.scheme")
12--schemeMgr:loadScheme("VanillaLook.scheme")
13--schemeMgr:loadScheme("SleekSpaceLook.scheme")
[6566]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
[6564]18schemeMgr:loadScheme("TaharezMenuWidgets.scheme")
[6567]19schemeMgr:loadScheme("TaharezHUDWidgets.scheme")
[6566]20
21-- Just a remaining test hack
[5491]22schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
23
24system:setDefaultMouseCursor("TaharezLook", "MouseArrow")
25system:setDefaultFont("BlueHighway-12")
[6564]26system:setDefaultTooltip("MenuWidgets/Tooltip")
[5491]27
28loadedGUIs = {}
[6417]29cursorVisibility = {}
30activeSheets = {}
31nrOfActiveSheets = 0
32root = nil
33bShowsCursor = false
34bHidePrevious = {}
[5491]35
[6417]36-- Require all tools
37require("GUITools")
38
[5491]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)
[6417]46        if loadedGuiNS == nil then
47            return
48        end
[5491]49        loadedGui = loadedGuiNS:load()
50        loadedGUIs[filename] = loadedGui
51        -- if there has no GUI been loaded yet, set new GUI as current
[5580]52        if table.getn(loadedGUIs) == 1 then
[5491]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
[6417]61function showGUI(filename, hidePrevious, bCursorVisible, ptr)
62    gui = showGUI(filename, hidePrevious, bCursorVisible)
[5491]63    gui.overlay = ptr
64end
65
[6544]66-- shows the specified GUI sheet and loads it if not loaded already
[6417]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
[5491]73        end
74    end
75
[6417]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()
[5491]92    else
[6417]93        hideCursor()
[5491]94    end
[6417]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
[6537]101            --orxonox.InputManager:getInstance():enterState("guiMouseOnly")
[6417]102            orxonox.HumanController:pauseControl()
103        end
104    end
[6537]105    orxonox.InputManager:getInstance():enterState(currentGUI.inputState)
106
[6417]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
[5491]120end
121
122function hideCursor()
[6417]123    if bShowsCursor==true then
124        bShowsCursor=false
125        cursor:hide()
126    end
[5491]127end
128
129function showCursor()
[6417]130    if bShowsCursor==false then
131        bShowsCursor=true
132        cursor:show()
133    end
[5491]134end
135
136function hideGUI(filename)
[6417]137    local currentGUI = loadedGUIs[filename]
138    if currentGUI == nil then
139        return
[5491]140    end
[6417]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
[6537]177        --orxonox.InputManager:getInstance():leaveState("guiMouseOnly")
[6417]178        orxonox.HumanController:resumeControl()
179        hideCursor()
180    end
[6537]181    orxonox.InputManager:getInstance():leaveState(currentGUI.inputState)
[5491]182end
[6417]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.