Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

svn:eol-style "native" for the gui scripts.

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