Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/media/gui/scripts/loadGUI_2.lua @ 5432

Last change on this file since 5432 was 5432, checked in by rgrieder, 15 years ago

Added inGameGUI test sheet.
Also removed workaround for the filename. Found another way by using executeString() in CEGUILua.

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1local schemeMgr = CEGUI.SchemeManager:getSingleton()
2local winMgr = 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")
13
14local current = nil
15local loadedGUIs = {}
16local showing
17
18datapath = "" -- points to media-folder (set after loading the script)
19
20-- function to add a reference to list of reference of loaded GUIs
21loadedGUIs.addGUI = function (gui)
22    loadedGUIs[#loadedGUIs+1] = gui
23end
24
25-- function which returns a GUI by name
26loadedGUIs.getGUIbyName = function (str)
27    for i = 1, #loadedGUIs, 1 do
28        if str == loadedGUIs[i].filename then
29            return loadedGUIs[i]
30        end
31    end
32    return nil
33end
34
35-- loads the GUI with the specified filename
36-- be sure to set the global variable "filename" before calling this function
37function loadGUI(filename)
38    -- check if it already exists
39    newlyLoaded = loadedGUIs:getGUIbyName(filename)
40    if newlyLoaded == nil then
41        dofile(datapath .. "gui/scripts/" .. filename .. ".lua")
42        newlyLoaded = winMgr:loadWindowLayout(layoutPath)
43        newlyLoaded.filename = filename
44        loadedGUIs:addGUI(newlyLoaded)
45        -- if there has no GUI been loaded yet, set new GUI as current
46        if #loadedGUIs == 1 then
47            current = loadedGUIs[1]
48            showing = false
49        end
50        -- hide new GUI as we do not want to show it accidentially
51        newlyLoaded:hide()
52    end
53    return newlyLoaded
54end
55
56-- shows the specified and loads it if not loaded already
57-- be sure to set the global variable "filename" before calling this function
58function showGUI(filename)
59    if current == nil or current.filename ~= filename then
60        current = loadedGUIs.getGUIbyName(filename)
61        if current == nil then
62            current = loadGUI(filename)
63        end
64        system:setGUISheet(current)
65    end
66    current:show()
67    cursor:show()
68    showing = true
69end
70
71function toggleGUI()
72    if showing == true then
73        current:hide()
74        cursor:hide()
75        showing = false
76    else
77        current:show()
78        cursor:show()
79        showing = true
80    end
81    return showing
82end
83
84function hideGUI()
85    current:hide()
86    showing = false
87end
Note: See TracBrowser for help on using the repository browser.