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 | |
---|
18 | datapath = "" -- points to media-folder (set after loading the script) |
---|
19 | |
---|
20 | -- function to add a reference to list of reference of loaded GUIs |
---|
21 | loadedGUIs.addGUI = function (gui) |
---|
22 | loadedGUIs[#loadedGUIs+1] = gui |
---|
23 | end |
---|
24 | |
---|
25 | -- function which returns a GUI by name |
---|
26 | loadedGUIs.getGUIbyName = function (str) |
---|
27 | print("number of GUIs loaded: " .. #loadedGUIs) |
---|
28 | for i = 1, #loadedGUIs, 1 do |
---|
29 | print("Checking GUI " .. loadedGUIs[i].filename) |
---|
30 | if str == loadedGUIs[i].filename then |
---|
31 | return loadedGUIs[i] |
---|
32 | end |
---|
33 | end |
---|
34 | return nil |
---|
35 | end |
---|
36 | |
---|
37 | -- loads the GUI with the specified filename |
---|
38 | -- be sure to set the global variable "filename" before calling this function |
---|
39 | function loadGUI(filename) |
---|
40 | -- 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 |
---|
45 | dofile(datapath .. "gui/scripts/" .. filename .. ".lua") |
---|
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 |
---|
57 | return newlyLoaded |
---|
58 | end |
---|
59 | |
---|
60 | -- shows the specified and loads it if not loaded already |
---|
61 | -- be sure to set the global variable "filename" before calling this function |
---|
62 | function showGUI(filename) |
---|
63 | print("about to show " .. filename) |
---|
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) |
---|
68 | if current == nil then |
---|
69 | current = loadGUI(filename) |
---|
70 | end |
---|
71 | system:setGUISheet(current) |
---|
72 | end |
---|
73 | print("Showing " .. filename) |
---|
74 | current:show() |
---|
75 | showing = true |
---|
76 | end |
---|
77 | |
---|
78 | function toggleGUI() |
---|
79 | if showing == true then |
---|
80 | current:hide() |
---|
81 | cursor:hide() |
---|
82 | showing = false |
---|
83 | else |
---|
84 | current:show() |
---|
85 | cursor:show() |
---|
86 | showing = true |
---|
87 | end |
---|
88 | return showing |
---|
89 | end |
---|
90 | |
---|
91 | function hideCursor() |
---|
92 | cursor:hide() |
---|
93 | end |
---|
94 | |
---|
95 | function showCursor() |
---|
96 | cursor:show() |
---|
97 | end |
---|
98 | |
---|
99 | 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) |
---|
104 | if current ~= nil then |
---|
105 | print("Hiding " .. filename) |
---|
106 | current:hide() |
---|
107 | showing = false |
---|
108 | end |
---|
109 | end |
---|