Changeset 5459
- Timestamp:
- Apr 13, 2009, 5:02:50 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
data/media/gui/scripts/loadGUI_2.lua
r5446 r5459 14 14 local current = nil 15 15 local loadedGUIs = {} 16 local showing 16 -- a bit more complex: GUI is now a class 17 GUI = {} 18 GUI.__index = GUI 19 20 -- hide function for the GUI 21 GUI.hide = function (self) 22 self.window:hide() 23 end 24 25 -- show function for the GUI 26 GUI.show = function (self) 27 self.window:show() 28 end 29 30 -- constructor of the GUI 31 GUI.new = function (gui, fname) 32 local newElement = { window = gui, filename = fname } 33 setmetatable(newElement, GUI) -- connects new element with class 34 return newElement 35 end 17 36 18 37 datapath = "" -- points to media-folder (set after loading the script) 19 20 -- function to add a reference to list of reference of loaded GUIs21 loadedGUIs.addGUI = function (gui)22 loadedGUIs[#loadedGUIs+1] = gui23 end24 25 -- function which returns a GUI by name26 loadedGUIs.getGUIbyName = function (str)27 print("number of GUIs loaded: " .. #loadedGUIs)28 for i = 1, #loadedGUIs, 1 do29 print("Checking GUI " .. loadedGUIs[i].filename)30 if str == loadedGUIs[i].filename then31 return loadedGUIs[i]32 end33 end34 return nil35 end36 38 37 39 -- loads the GUI with the specified filename … … 39 41 function loadGUI(filename) 40 42 -- check if it already exists 41 print("about to load " .. filename) 42 print("search for GUI " .. filename) 43 newlyLoaded = loadedGUIs:getGUIbyName(filename) 44 if newlyLoaded == nil then 43 --gui = loadedGUIs:getGUIbyName(filename) 44 gui = loadedGUIs[filename] 45 if gui == nil then 45 46 dofile(datapath .. "gui/scripts/" .. filename .. ".lua") 46 newlyLoaded= winMgr:loadWindowLayout(layoutPath)47 newlyLoaded.filename = filename48 loadedGUIs :addGUI(newlyLoaded)47 win = winMgr:loadWindowLayout(layoutPath) 48 gui = GUI.new(win, filename) 49 loadedGUIs[filename] = gui 49 50 -- if there has no GUI been loaded yet, set new GUI as current 50 51 if #loadedGUIs == 1 then … … 53 54 end 54 55 -- hide new GUI as we do not want to show it accidentially 55 newlyLoaded:hide()56 gui:hide() 56 57 end 57 return newlyLoaded58 return gui 58 59 end 59 60 … … 61 62 -- be sure to set the global variable "filename" before calling this function 62 63 function showGUI(filename) 63 print("about to show " .. filename)64 64 if current == nil or current.filename ~= filename then 65 print("current not set")66 print("search for GUI " .. filename)67 current = loadedGUIs .getGUIbyName(filename)65 if current ~= nil then 66 end 67 current = loadedGUIs[filename] 68 68 if current == nil then 69 69 current = loadGUI(filename) 70 70 end 71 system:setGUISheet(current )71 system:setGUISheet(current.window) 72 72 end 73 print("Showing " .. filename)74 73 current:show() 75 74 showing = true … … 98 97 99 98 function hideGUI(filename) 100 print("about to hide " .. filename) 101 print("search for GUI " .. filename) 102 current = loadedGUIs.getGUIbyName(filename) 103 print("current is: " .. current) 99 current = loadedGUIs[filename] 104 100 if current ~= nil then 105 print("Hiding " .. filename)106 101 current:hide() 107 102 showing = false
Note: See TracChangeset
for help on using the changeset viewer.