Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menu/data/gui/scripts/InitialiseGUI.lua @ 6313

Last change on this file since 6313 was 6148, checked in by cmueri, 15 years ago

fix

  • Property svn:eol-style set to native
File size: 5.3 KB
RevLine 
[5491]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")
[5527]13system:setDefaultTooltip("TaharezLook/Tooltip")
[5491]14
15loadedGUIs = {}
[6024]16cursorVisibility = {}
17activeSheets = {}
18nrOfActiveSheets = 0
19root = nil
20bShowsCursor = false
[6032]21bHidePrevious = {}
[5491]22
[6048]23-- Require all tools
24require("GUITools")
25
[5491]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)
[6048]33        if loadedGuiNS == nil then
34            return
35        end
[5491]36        loadedGui = loadedGuiNS:load()
37        loadedGUIs[filename] = loadedGui
38        -- if there has no GUI been loaded yet, set new GUI as current
[5580]39        if table.getn(loadedGUIs) == 1 then
[5491]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
[6032]48function showGUI(filename, hidePrevious, bCursorVisible, ptr)
49    gui = showGUI(filename, hidePrevious, bCursorVisible)
[5491]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
[6032]55function showGUI(filename, hidePrevious, bCursorVisible)
[6024]56    if bCursorVisible == nil then
[6032]57        bCursorVisible = true
[5491]58    end
59
[6024]60    if root == nil then
[6032]61        setBackground("")
[6024]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()
[5491]76    else
[6024]77        hideCursor()
[5491]78    end
[6024]79   
[6032]80    if find( activeSheets, filename ) ~= nil then
81        table.remove( activeSheets, find( activeSheets, filename ) )
82        nrOfActiveSheets = nrOfActiveSheets - 1
83    end
[6024]84    nrOfActiveSheets = nrOfActiveSheets + 1
85    table.insert(activeSheets, filename)
86    activeSheets[nrOfActiveSheets] = filename
[6032]87    bHidePrevious[filename]=hidePrevious
88    cursorVisibility[filename] = bCursorVisible
[6024]89   
[6032]90    if hidePrevious == true then
91        for i=1,nrOfActiveSheets-1 do
92            loadedGUIs[ activeSheets[i] ]:hide()
93        end
94    end
[6024]95    currentGUI:show()
96    return currentGUI
[5491]97end
98
99function hideCursor()
[6024]100    if bShowsCursor==true then
101        bShowsCursor=false
102        cursor:hide()
103    end
[5491]104end
105
106function showCursor()
[6024]107    if bShowsCursor==false then
108        bShowsCursor=true
109        cursor:show()
110    end
[5491]111end
112
113function hideGUI(filename)
[6024]114    local currentGUI = loadedGUIs[filename]
115    if currentGUI == nil then
116        return
[5491]117    end
[6024]118    currentGUI:hide()
[6032]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
[6024]130    root:removeChildWindow(currentGUI.window)
[6032]131    local i=1
[6024]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
[6032]152    bHidePrevious[filename] = nil
[5491]153end
[6032]154
[6048]155function keyESC()
156    orxonox.CommandExecutor:execute("hideGUI "..activeSheets[nrOfActiveSheets])
157end
158
[6032]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
[6148]176        while root:getChildCount()~=0 do
177            debug(root:getChildCount())
178            child = root:getChildAtIdx(0)
[6032]179            root:removeChildWindow(child)
180            newroot:addChildWindow(child)
181        end
182        winMgr:destroyWindow(root)
183    end
184    newroot:show()
185    root = newroot
186end
187
188function find(table, value)
189    local i=0
190    while table[i] ~= nil do
191        if table[i]==value then
192            return i
193        else
194            i=i+1
195        end
196    end
197    return nil
198end
Note: See TracBrowser for help on using the repository browser.