Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5520 was 5482, checked in by rgrieder, 16 years ago

Fixed lua code to have compatibility with Lua 5.0

  • Property svn:eol-style set to native
File size: 2.7 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 = {}
[5459]16-- a bit more complex: GUI is now a class
17GUI = {}
18GUI.__index = GUI
[5432]19
[5459]20-- hide function for the GUI
21GUI.hide = function (self)
22    self.window:hide()
23end
[5427]24
[5459]25-- show function for the GUI
26GUI.show = function (self)
27    self.window:show()
[5427]28end
29
[5459]30-- constructor of the GUI
31GUI.new = function (gui, fname)
32    local newElement = { window = gui, filename = fname }
33    setmetatable(newElement, GUI) -- connects new element with class
34    return newElement
[5430]35end
[5427]36
[5459]37datapath = "" -- points to media-folder (set after loading the script)
38
[5427]39-- loads the GUI with the specified filename
[5430]40-- be sure to set the global variable "filename" before calling this function
[5432]41function loadGUI(filename)
[5427]42    -- check if it already exists
[5459]43    --gui = loadedGUIs:getGUIbyName(filename)
44    gui = loadedGUIs[filename]
45    if gui == nil then
[5432]46        dofile(datapath .. "gui/scripts/" .. filename .. ".lua")
[5459]47        win = winMgr:loadWindowLayout(layoutPath)
48        gui = GUI.new(win, filename)
49        loadedGUIs[filename] = gui
[5427]50        -- if there has no GUI been loaded yet, set new GUI as current
[5482]51        if table.getn(loadedGUIs) == 1 then
[5427]52            current = loadedGUIs[1]
53            showing = false
54        end
55        -- hide new GUI as we do not want to show it accidentially
[5459]56        gui:hide()
[5427]57    end
[5459]58    return gui
[5414]59end
60
[5427]61-- shows the specified and loads it if not loaded already
62-- be sure to set the global variable "filename" before calling this function
[5432]63function showGUI(filename)
[5427]64    if current == nil or current.filename ~= filename then
[5459]65        if current ~= nil then
66        end
67        current = loadedGUIs[filename]
[5427]68        if current == nil then
69            current = loadGUI(filename)
70        end
[5459]71        system:setGUISheet(current.window)
[5427]72    end
73    current:show()
74    showing = true
75end
[5414]76
77function toggleGUI()
78    if showing == true then
[5427]79        current:hide()
80        cursor:hide()
[5414]81        showing = false
82    else
[5427]83        current:show()
84        cursor:show()
[5414]85        showing = true
86    end
[5427]87    return showing
[5430]88end
89
[5446]90function hideCursor()
91    cursor:hide()
[5430]92end
[5446]93
94function showCursor()
95    cursor:show()
96end
97
98function hideGUI(filename)
[5459]99    current = loadedGUIs[filename]
[5446]100    if current ~= nil then
101        current:hide()
102        showing = false
103    end
104end
Note: See TracBrowser for help on using the repository browser.