1 | local schemeMgr = CEGUI.SchemeManager:getSingleton() |
---|
2 | 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 | system:setDefaultTooltip("TaharezLook/Tooltip") |
---|
14 | |
---|
15 | loadedGUIs = {} |
---|
16 | cursorVisibility = {} |
---|
17 | activeSheets = {} |
---|
18 | nrOfActiveSheets = 0 |
---|
19 | root = nil |
---|
20 | bShowsCursor = false |
---|
21 | bHidePrevious = {} |
---|
22 | |
---|
23 | -- loads the GUI with the specified filename |
---|
24 | -- be sure to set the global variable "filename" before calling this function |
---|
25 | function loadGUI(filename) |
---|
26 | -- check if it already exists |
---|
27 | loadedGui = loadedGUIs[filename] |
---|
28 | if loadedGui == nil then |
---|
29 | loadedGuiNS = require(filename) |
---|
30 | loadedGui = loadedGuiNS:load() |
---|
31 | loadedGUIs[filename] = loadedGui |
---|
32 | -- if there has no GUI been loaded yet, set new GUI as current |
---|
33 | if table.getn(loadedGUIs) == 1 then |
---|
34 | current = loadedGUIs[1] |
---|
35 | end |
---|
36 | -- hide new GUI as we do not want to show it accidentially |
---|
37 | loadedGui:hide() |
---|
38 | end |
---|
39 | return loadedGui |
---|
40 | end |
---|
41 | |
---|
42 | function showGUI(filename, hidePrevious, bCursorVisible, ptr) |
---|
43 | gui = showGUI(filename, hidePrevious, bCursorVisible) |
---|
44 | gui.overlay = ptr |
---|
45 | end |
---|
46 | |
---|
47 | -- shows the specified and loads it if not loaded already |
---|
48 | -- be sure to set the global variable "filename" before calling this function |
---|
49 | function showGUI(filename, hidePrevious, bCursorVisible) |
---|
50 | if bCursorVisible == nil then |
---|
51 | bCursorVisible = true |
---|
52 | end |
---|
53 | |
---|
54 | if root == nil then |
---|
55 | setBackground("") |
---|
56 | end |
---|
57 | |
---|
58 | local currentGUI = loadedGUIs[filename] |
---|
59 | if(currentGUI == nil) then |
---|
60 | currentGUI = loadGUI(filename) |
---|
61 | end |
---|
62 | |
---|
63 | if(root:isChild(currentGUI.window)) then |
---|
64 | root:removeChildWindow(currentGUI.window) |
---|
65 | end |
---|
66 | root:addChildWindow(currentGUI.window) |
---|
67 | |
---|
68 | if bCursorVisible then |
---|
69 | showCursor() |
---|
70 | else |
---|
71 | hideCursor() |
---|
72 | end |
---|
73 | |
---|
74 | if find( activeSheets, filename ) ~= nil then |
---|
75 | table.remove( activeSheets, find( activeSheets, filename ) ) |
---|
76 | nrOfActiveSheets = nrOfActiveSheets - 1 |
---|
77 | end |
---|
78 | nrOfActiveSheets = nrOfActiveSheets + 1 |
---|
79 | table.insert(activeSheets, filename) |
---|
80 | activeSheets[nrOfActiveSheets] = filename |
---|
81 | bHidePrevious[filename]=hidePrevious |
---|
82 | cursorVisibility[filename] = bCursorVisible |
---|
83 | |
---|
84 | if hidePrevious == true then |
---|
85 | for i=1,nrOfActiveSheets-1 do |
---|
86 | loadedGUIs[ activeSheets[i] ]:hide() |
---|
87 | end |
---|
88 | end |
---|
89 | currentGUI:show() |
---|
90 | return currentGUI |
---|
91 | end |
---|
92 | |
---|
93 | function hideCursor() |
---|
94 | if bShowsCursor==true then |
---|
95 | bShowsCursor=false |
---|
96 | cursor:hide() |
---|
97 | end |
---|
98 | end |
---|
99 | |
---|
100 | function showCursor() |
---|
101 | if bShowsCursor==false then |
---|
102 | bShowsCursor=true |
---|
103 | cursor:show() |
---|
104 | end |
---|
105 | end |
---|
106 | |
---|
107 | function hideGUI(filename) |
---|
108 | local currentGUI = loadedGUIs[filename] |
---|
109 | if currentGUI == nil then |
---|
110 | return |
---|
111 | end |
---|
112 | currentGUI:hide() |
---|
113 | if bHidePrevious[filename] == true then |
---|
114 | local i = nrOfActiveSheets-1 |
---|
115 | while i>0 do |
---|
116 | loadedGUIs[ activeSheets[i] ]:show() |
---|
117 | if bHidePrevious[filename]==true then |
---|
118 | break |
---|
119 | else |
---|
120 | i=i-1 |
---|
121 | end |
---|
122 | end |
---|
123 | end |
---|
124 | root:removeChildWindow(currentGUI.window) |
---|
125 | local i=1 |
---|
126 | while activeSheets[i] do |
---|
127 | if activeSheets[i+1] == nil then |
---|
128 | if activeSheets[i-1] ~= nil then |
---|
129 | if cursorVisibility[ activeSheets[i-1] ] == true then |
---|
130 | showCursor() |
---|
131 | else |
---|
132 | hideCursor() |
---|
133 | end |
---|
134 | else |
---|
135 | hideCursor() |
---|
136 | end |
---|
137 | end |
---|
138 | if activeSheets[i] == filename then |
---|
139 | table.remove( activeSheets, i ) |
---|
140 | nrOfActiveSheets = nrOfActiveSheets-1 |
---|
141 | else |
---|
142 | i = i+1 |
---|
143 | end |
---|
144 | end |
---|
145 | cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table |
---|
146 | bHidePrevious[filename] = nil |
---|
147 | end |
---|
148 | |
---|
149 | function setBackground(filename) |
---|
150 | local newroot |
---|
151 | if root ~= nil then |
---|
152 | root:rename("oldRootWindow") |
---|
153 | end |
---|
154 | if filename ~= "" then |
---|
155 | newroot = winMgr:loadWindowLayout(filename .. ".layout") |
---|
156 | newroot:rename("AbsoluteRootWindow") |
---|
157 | system:setGUISheet(newroot) |
---|
158 | else |
---|
159 | newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow") |
---|
160 | newroot:setProperty("Alpha", "0.0") |
---|
161 | newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0))) |
---|
162 | system:setGUISheet(newroot) |
---|
163 | end |
---|
164 | if root ~= nil then |
---|
165 | local child |
---|
166 | for i=0,root:getChildCount()-1 do |
---|
167 | child = root:getChildAtIdx(i) |
---|
168 | root:removeChildWindow(child) |
---|
169 | newroot:addChildWindow(child) |
---|
170 | end |
---|
171 | winMgr:destroyWindow(root) |
---|
172 | end |
---|
173 | newroot:show() |
---|
174 | root = newroot |
---|
175 | end |
---|
176 | |
---|
177 | function find(table, value) |
---|
178 | local i=0 |
---|
179 | while table[i] ~= nil do |
---|
180 | if table[i]==value then |
---|
181 | return i |
---|
182 | else |
---|
183 | i=i+1 |
---|
184 | end |
---|
185 | end |
---|
186 | return nil |
---|
187 | end |
---|