Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource2/media/gui/scripts/loadGUI_2.lua @ 5295

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

Added most of the text based files of the media directory (the file I deleted in the previous commit of the media repo) with svn:eol-style=native

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