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
RevLine 
[5430]1local schemeMgr = CEGUI.SchemeManager:getSingleton()
2local winMgr = CEGUI.WindowManager:getSingleton()
3local logger = CEGUI.Logger:getSingleton()
[5427]4local system = CEGUI.System:getSingleton()
[5430]5local cursor = CEGUI.MouseCursor:getSingleton()
6
[5427]7schemeMgr:loadScheme("TaharezLookSkin.scheme")
8-- load scheme with our own images
9schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
10
[5430]11system:setDefaultMouseCursor("TaharezLook", "MouseArrow")
12system:setDefaultFont("BlueHighway-12")
[5414]13
[5427]14local current = nil
15local loadedGUIs = {}
16local showing
[5432]17
[5427]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
[5430]33end
[5427]34
35-- loads the GUI with the specified filename
[5430]36-- be sure to set the global variable "filename" before calling this function
[5432]37function loadGUI(filename)
[5427]38    -- check if it already exists
39    newlyLoaded = loadedGUIs:getGUIbyName(filename)
40    if newlyLoaded == nil then
[5432]41        dofile(datapath .. "gui/scripts/" .. filename .. ".lua")
[5427]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
[5430]53    return newlyLoaded
[5414]54end
55
[5427]56-- shows the specified and loads it if not loaded already
57-- be sure to set the global variable "filename" before calling this function
[5432]58function showGUI(filename)
[5427]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
[5414]70
71function toggleGUI()
72    if showing == true then
[5427]73        current:hide()
74        cursor:hide()
[5414]75        showing = false
76    else
[5427]77        current:show()
78        cursor:show()
[5414]79        showing = true
80    end
[5427]81    return showing
[5430]82end
83
[5427]84function hideGUI()
85    current:hide()
[5430]86    showing = false
87end
Note: See TracBrowser for help on using the repository browser.