1 | local schemeMgr = CEGUI.SchemeManager:getSingleton() |
---|
2 | local winMgr = CEGUI.WindowManager:getSingleton() |
---|
3 | local logger = CEGUI.Logger:getSingleton() |
---|
4 | local system = CEGUI.System:getSingleton() |
---|
5 | local cursor = CEGUI.MouseCursor:getSingleton() |
---|
6 | |
---|
7 | schemeMgr:loadScheme("TaharezLookSkin.scheme") |
---|
8 | -- load scheme with our own images |
---|
9 | schemeMgr:loadScheme("OrxonoxGUIScheme.scheme") |
---|
10 | |
---|
11 | system:setDefaultMouseCursor("TaharezLook", "MouseArrow") |
---|
12 | system:setDefaultFont("BlueHighway-12") |
---|
13 | |
---|
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 |
---|
34 | end |
---|
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 |
---|
55 | end |
---|
56 | |
---|
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 |
---|
71 | |
---|
72 | function toggleGUI() |
---|
73 | if showing == true then |
---|
74 | current:hide() |
---|
75 | cursor:hide() |
---|
76 | showing = false |
---|
77 | else |
---|
78 | current:show() |
---|
79 | cursor:show() |
---|
80 | showing = true |
---|
81 | end |
---|
82 | return showing |
---|
83 | end |
---|
84 | |
---|
85 | function hideGUI() |
---|
86 | current:hide() |
---|
87 | showing = false |
---|
88 | end |
---|