Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5452 was 5446, checked in by bknecht, 16 years ago

added some debug-output to fix stuff I ran into with LUa on Tardis. Not solved unfortunately. Game crashes when using the showingamegui command

  • Property svn:eol-style set to native
File size: 3.1 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)
[5446]27    print("number of GUIs loaded: " .. #loadedGUIs)
[5427]28    for i = 1, #loadedGUIs, 1 do
[5446]29        print("Checking GUI " .. loadedGUIs[i].filename)
[5427]30        if str == loadedGUIs[i].filename then
31            return loadedGUIs[i]
32        end
33    end
34    return nil
[5430]35end
[5427]36
37-- loads the GUI with the specified filename
[5430]38-- be sure to set the global variable "filename" before calling this function
[5432]39function loadGUI(filename)
[5427]40    -- check if it already exists
[5446]41    print("about to load " .. filename)
42    print("search for GUI " .. filename)
[5427]43    newlyLoaded = loadedGUIs:getGUIbyName(filename)
44    if newlyLoaded == nil then
[5432]45        dofile(datapath .. "gui/scripts/" .. filename .. ".lua")
[5427]46        newlyLoaded = winMgr:loadWindowLayout(layoutPath)
47        newlyLoaded.filename = filename
48        loadedGUIs:addGUI(newlyLoaded)
49        -- if there has no GUI been loaded yet, set new GUI as current
50        if #loadedGUIs == 1 then
51            current = loadedGUIs[1]
52            showing = false
53        end
54        -- hide new GUI as we do not want to show it accidentially
55        newlyLoaded:hide()
56    end
[5430]57    return newlyLoaded
[5414]58end
59
[5427]60-- shows the specified and loads it if not loaded already
61-- be sure to set the global variable "filename" before calling this function
[5432]62function showGUI(filename)
[5446]63    print("about to show " .. filename)
[5427]64    if current == nil or current.filename ~= filename then
[5446]65        print("current not set")
66        print("search for GUI " .. filename)
[5427]67        current = loadedGUIs.getGUIbyName(filename)
68        if current == nil then
69            current = loadGUI(filename)
70        end
71        system:setGUISheet(current)
72    end
[5446]73    print("Showing " .. filename)
[5427]74    current:show()
75    showing = true
76end
[5414]77
78function toggleGUI()
79    if showing == true then
[5427]80        current:hide()
81        cursor:hide()
[5414]82        showing = false
83    else
[5427]84        current:show()
85        cursor:show()
[5414]86        showing = true
87    end
[5427]88    return showing
[5430]89end
90
[5446]91function hideCursor()
92    cursor:hide()
[5430]93end
[5446]94
95function showCursor()
96    cursor:show()
97end
98
99function hideGUI(filename)
100    print("about to hide " .. filename)
101    print("search for GUI " .. filename)
102    current = loadedGUIs.getGUIbyName(filename)
103    print("current is: " .. current)
104    if current ~= nil then
105        print("Hiding " .. filename)
106        current:hide()
107        showing = false
108    end
109end
Note: See TracBrowser for help on using the repository browser.