Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ingamemenu/data/gui/scripts/InitialiseGUI.lua @ 6023

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

clean cursor handling in GUIManager/lua code
change in output level of lua error messages

  • Property svn:eol-style set to native
File size: 3.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
21
22-- loads the GUI with the specified filename
23-- be sure to set the global variable "filename" before calling this function
24function loadGUI(filename)
25    -- check if it already exists
26    loadedGui = loadedGUIs[filename]
27    if loadedGui == nil then
28        loadedGuiNS = require(filename)
29        loadedGui = loadedGuiNS:load()
30        loadedGUIs[filename] = loadedGui
31        -- if there has no GUI been loaded yet, set new GUI as current
32        if table.getn(loadedGUIs) == 1 then
33            current = loadedGUIs[1]
34            showing = false
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
42function showGUI(filename, bCursorVisible, ptr)
43    gui = showGUI(filename, bCursorVisible)
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
49function showGUI(filename, bCursorVisible)
50--     bCursorVisibile=false
51    if bCursorVisible == nil then
52        cursorVisibility= true
53    end
54
55    if root == nil then
56        root = winMgr:createWindow("TaharezLook/StaticImage", "AbsoluteRootWindow")
57        root:setProperty("Alpha", "0.0")
58        root:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))
59        system:setGUISheet(root)
60    end
61
62    local currentGUI = loadedGUIs[filename]
63    if(currentGUI == nil) then
64        currentGUI = loadGUI(filename)
65    end
66
67    if(root:isChild(currentGUI.window)) then
68        root:removeChildWindow(currentGUI.window)
69    end
70    root:addChildWindow(currentGUI.window)
71
72    if bCursorVisible then
73        showCursor()
74    else
75        hideCursor()
76    end
77    cursorVisibility[filename]=bCursorVisible
78   
79    nrOfActiveSheets = nrOfActiveSheets + 1
80    table.insert(activeSheets, filename)
81    activeSheets[nrOfActiveSheets] = filename
82   
83    currentGUI:show()
84    showing = true
85    return currentGUI
86end
87
88function hideCursor()
89    if bShowsCursor==true then
90        bShowsCursor=false
91        cursor:hide()
92    end
93end
94
95function showCursor()
96    if bShowsCursor==false then
97        bShowsCursor=true
98        cursor:show()
99    end
100end
101
102function hideGUI(filename)
103    local currentGUI = loadedGUIs[filename]
104    if currentGUI == nil then
105        return
106    end
107    currentGUI:hide()
108    root:removeChildWindow(currentGUI.window)
109    showing = false
110    i=1
111    while activeSheets[i] do
112        if activeSheets[i+1] == nil then
113            if activeSheets[i-1] ~= nil then
114                if cursorVisibility[ activeSheets[i-1] ] == true then
115                    showCursor()
116                else
117                    hideCursor()
118                end
119            else
120                hideCursor()
121            end
122        end
123        if activeSheets[i] == filename then
124            table.remove( activeSheets, i )
125            nrOfActiveSheets = nrOfActiveSheets-1
126        else
127            i = i+1
128        end
129    end
130    cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table
131end
Note: See TracBrowser for help on using the repository browser.