Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6044 was 6036, checked in by scheusso, 16 years ago

some changes to make GUI showing/hiding with possible coverage of current shown GUIs now possible

  • Property svn:eol-style set to native
File size: 5.1 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
23-- loads the GUI with the specified filename
24-- be sure to set the global variable "filename" before calling this function
25function loadGUI(filename)
26    -- check if it already exists
27    loadedGui = loadedGUIs[filename]
28    if loadedGui == nil then
29        loadedGuiNS = require(filename)
30        loadedGui = loadedGuiNS:load()
31        loadedGUIs[filename] = loadedGui
32        -- if there has no GUI been loaded yet, set new GUI as current
[5580]33        if table.getn(loadedGUIs) == 1 then
[5491]34            current = loadedGUIs[1]
35        end
36        -- hide new GUI as we do not want to show it accidentially
37        loadedGui:hide()
38    end
39    return loadedGui
40end
41
[6032]42function showGUI(filename, hidePrevious, bCursorVisible, ptr)
43    gui = showGUI(filename, hidePrevious, bCursorVisible)
[5491]44    gui.overlay = ptr
45end
46
47-- shows the specified and loads it if not loaded already
48-- be sure to set the global variable "filename" before calling this function
[6032]49function showGUI(filename, hidePrevious, bCursorVisible)
[6024]50    if bCursorVisible == nil then
[6032]51        bCursorVisible = true
[5491]52    end
53
[6024]54    if root == nil then
[6032]55        setBackground("")
[6024]56    end
57
58    local currentGUI = loadedGUIs[filename]
59    if(currentGUI == nil) then
60        currentGUI = loadGUI(filename)
61    end
62
63    if(root:isChild(currentGUI.window)) then
64        root:removeChildWindow(currentGUI.window)
65    end
66    root:addChildWindow(currentGUI.window)
67
68    if bCursorVisible then
69        showCursor()
[5491]70    else
[6024]71        hideCursor()
[5491]72    end
[6024]73   
[6032]74    if find( activeSheets, filename ) ~= nil then
75        table.remove( activeSheets, find( activeSheets, filename ) )
76        nrOfActiveSheets = nrOfActiveSheets - 1
77    end
[6024]78    nrOfActiveSheets = nrOfActiveSheets + 1
79    table.insert(activeSheets, filename)
80    activeSheets[nrOfActiveSheets] = filename
[6032]81    bHidePrevious[filename]=hidePrevious
82    cursorVisibility[filename] = bCursorVisible
[6024]83   
[6032]84    if hidePrevious == true then
85        for i=1,nrOfActiveSheets-1 do
86            loadedGUIs[ activeSheets[i] ]:hide()
87        end
88    end
[6024]89    currentGUI:show()
90    return currentGUI
[5491]91end
92
93function hideCursor()
[6024]94    if bShowsCursor==true then
95        bShowsCursor=false
96        cursor:hide()
97    end
[5491]98end
99
100function showCursor()
[6024]101    if bShowsCursor==false then
102        bShowsCursor=true
103        cursor:show()
104    end
[5491]105end
106
107function hideGUI(filename)
[6024]108    local currentGUI = loadedGUIs[filename]
109    if currentGUI == nil then
110        return
[5491]111    end
[6024]112    currentGUI:hide()
[6032]113    if bHidePrevious[filename] == true then
114        local i = nrOfActiveSheets-1
115        while i>0 do
116            loadedGUIs[ activeSheets[i] ]:show()
117            if bHidePrevious[filename]==true then
118                break
119            else
120                i=i-1
121            end
122        end
123    end
[6024]124    root:removeChildWindow(currentGUI.window)
[6032]125    local i=1
[6024]126    while activeSheets[i] do
127        if activeSheets[i+1] == nil then
128            if activeSheets[i-1] ~= nil then
129                if cursorVisibility[ activeSheets[i-1] ] == true then
130                    showCursor()
131                else
132                    hideCursor()
133                end
134            else
135                hideCursor()
136            end
137        end
138        if activeSheets[i] == filename then
139            table.remove( activeSheets, i )
140            nrOfActiveSheets = nrOfActiveSheets-1
141        else
142            i = i+1
143        end
144    end
145    cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table
[6032]146    bHidePrevious[filename] = nil
[5491]147end
[6032]148
149function setBackground(filename)
150    local newroot
151    if root ~= nil then
152        root:rename("oldRootWindow")
153    end
154    if filename ~= "" then
155        newroot = winMgr:loadWindowLayout(filename .. ".layout")
156        newroot:rename("AbsoluteRootWindow")
157        system:setGUISheet(newroot)
158    else
159        newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow")
160        newroot:setProperty("Alpha", "0.0")
161        newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))
162        system:setGUISheet(newroot)
163    end
164    if root ~= nil then
165        local child
166        for i=0,root:getChildCount()-1 do
167            child = root:getChildAtIdx(i)
168            root:removeChildWindow(child)
169            newroot:addChildWindow(child)
170        end
171        winMgr:destroyWindow(root)
172    end
173    newroot:show()
174    root = newroot
175end
176
177function find(table, value)
178    local i=0
179    while table[i] ~= nil do
180        if table[i]==value then
181            return i
182        else
183            i=i+1
184        end
185    end
186    return nil
187end
Note: See TracBrowser for help on using the repository browser.