[5162] | 1 | local schemeMgr = CEGUI.SchemeManager:getSingleton() |
---|
| 2 | local winMgr = CEGUI.WindowManager:getSingleton() |
---|
| 3 | local logger = CEGUI.Logger:getSingleton() |
---|
[5427] | 4 | local system = CEGUI.System:getSingleton() |
---|
| 5 | local cursor = CEGUI.MouseCursor:getSingleton() |
---|
[5162] | 6 | |
---|
[5427] | 7 | schemeMgr:loadScheme("TaharezLookSkin.scheme") |
---|
| 8 | -- load scheme with our own images |
---|
| 9 | schemeMgr:loadScheme("OrxonoxGUIScheme.scheme") |
---|
| 10 | |
---|
[5162] | 11 | system:setDefaultMouseCursor("TaharezLook", "MouseArrow") |
---|
| 12 | system:setDefaultFont("BlueHighway-12") |
---|
[5414] | 13 | |
---|
[5427] | 14 | local current = nil |
---|
| 15 | local loadedGUIs = {} |
---|
| 16 | local showing |
---|
| 17 | -- we cannot directly call functions with parameters and so need this as a global variable, which sucks of course |
---|
| 18 | filename = "" |
---|
| 19 | datapath = "" -- points to media-folder (set after loading the script) |
---|
| 20 | |
---|
| 21 | -- function to add a reference to list of reference of loaded GUIs |
---|
| 22 | loadedGUIs.addGUI = function (gui) |
---|
| 23 | loadedGUIs[#loadedGUIs+1] = gui |
---|
| 24 | end |
---|
| 25 | |
---|
| 26 | -- function which returns a GUI by name |
---|
| 27 | loadedGUIs.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 |
---|
[5162] | 34 | end |
---|
[5427] | 35 | |
---|
| 36 | -- loads the GUI with the specified filename |
---|
| 37 | -- be sure to set the global variable "filename" before calling this function |
---|
| 38 | function 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 |
---|
[5414] | 55 | end |
---|
| 56 | |
---|
[5427] | 57 | -- shows the specified and loads it if not loaded already |
---|
| 58 | -- be sure to set the global variable "filename" before calling this function |
---|
| 59 | function 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 |
---|
| 70 | end |
---|
[5414] | 71 | |
---|
| 72 | function toggleGUI() |
---|
| 73 | if showing == true then |
---|
[5427] | 74 | current:hide() |
---|
| 75 | cursor:hide() |
---|
[5414] | 76 | showing = false |
---|
| 77 | else |
---|
[5427] | 78 | current:show() |
---|
| 79 | cursor:show() |
---|
[5414] | 80 | showing = true |
---|
| 81 | end |
---|
[5427] | 82 | return showing |
---|
[5162] | 83 | end |
---|
| 84 | |
---|
[5427] | 85 | function hideGUI() |
---|
| 86 | current:hide() |
---|
| 87 | showing = false |
---|
[5162] | 88 | end |
---|