Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/data/gui/scripts/InitialiseGUI.lua @ 6153

Last change on this file since 6153 was 6153, checked in by scheusso, 14 years ago

some fixes in weapon system / weapons
fabian: projectiles also spawn on wrong position in standalone mode

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