Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menuanimations/data/gui/scripts/InitialiseGUI.lua @ 7660

Last change on this file since 7660 was 6048, checked in by scheusso, 15 years ago

ESC handling in ingame menu: if theres already an opened GUI sheet then hide it, if not open the ingame menu
in mainmenu everything should remain the same

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