Changeset 8079 for code/trunk/data/gui/scripts/GUITools.lua
- Timestamp:
- Mar 15, 2011, 9:47:11 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/data/gui/scripts/GUITools.lua
r7913 r8079 54 54 return height 55 55 end 56 57 --function to iterate through a menu sheet by using arrowkeys58 59 --@arguments:60 -- list: 2-dimensional table, arguments are items that contain a button and its function61 -- !!note: each button can only be in the list once!!62 -- code: code of any key on the keyboard63 -- P: menusheet64 -- n: number of rows of the buttontable65 -- m: number of colums of the buttontable66 67 function buttonIteratorHelper(list, code, P, n, m)68 69 --after a key (down,up,left,right) is pressed the index of the current button has to be updated70 71 --key down72 if code == "208" then73 if P.index < 0 then -- initial status74 P.index = 075 P.oldindex = -176 else77 P.oldindex = P.index78 P.index = (P.index + m) % (m*n) --modulo operation works as a "wrap around" in the button menu79 80 while list[P.index+1] == nil do81 P.oldindex = P.index82 P.index = (P.index + m) % (m*n)83 end84 end85 86 --key up87 elseif code == "200" then88 if P.index < 0 then89 P.index = 090 P.oldindex = -191 elseif(P.index == 0) then92 P.oldindex = P.index93 P.index = m*n-m94 95 while list[P.index+1] == nil do96 P.oldindex = P.index97 P.index = (P.index-m)%(m*n)98 end99 else100 P.oldindex = P.index101 P.index = (P.index -m) % (m*n)102 103 while list[P.index+1] == nil do104 P.oldindex = P.index105 P.index = (P.index-m)%(m*n)106 end107 end108 109 --key right110 elseif code == "205" then111 if P.index < 0 then112 P.index = 0113 P.oldindex = -1114 elseif (P.index+1) % m == 0 then -- we are at the right-end of a row115 P.oldindex = P.index116 P.index = P.index + 1 -m117 118 while list[P.index+1] == nil do119 P.oldindex = P.index120 P.index = P.index + 1121 end122 else123 P.oldindex = P.index124 P.index = P.index + 1125 126 while list[P.index+1] == nil do127 if (P.index+1) % m == 0 then -- we are at the right-end of a row128 P.oldindex = P.index129 P.index = P.index + 1-m130 131 else132 P.oldindex = P.index133 P.index = P.index + 1134 end135 end136 end137 138 --key left139 elseif code == "203" then140 if P.index < 0 then141 P.index = 0142 P.oldindex = -1143 elseif P.index % m == 0 then -- we are at the left-end of a row144 P.oldindex = P.index145 P.index = P.index +m-1146 147 while list[P.index+1] == nil do148 P.oldindex = P.index149 P.index = P.index -1150 end151 else152 P.oldindex = P.index153 P.index = P.index -1154 155 while list[P.index+1] == nil do156 if P.index % m == 0 then -- we are at the left-end of a row157 P.oldindex = P.index158 P.index = P.index -1 + m159 else160 P.oldindex = P.index161 P.index = P.index -1162 end163 end164 end165 end166 167 --to update the new current button168 if (code == "208" or code == "200" or code == "203" or code == "205") and P.oldindex~= P.index then169 170 local system = CEGUI.System:getSingleton()171 local window = winMgr:getWindow("orxonox/MainMenuBackground")172 173 local item = list[P.index+1]174 local child = item["button"]175 local s = child:getProperty("NormalImageRightEdge")176 177 --teste ob der Button nicht schon gehighlightet ist178 if string.sub(s,string.len(s)-8,string.len(s)) == "Highlight" then179 --nop180 else181 child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-7) .. "Highlight")182 child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-7) .. "Highlight")183 child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-7) .. "Highlight")184 if P.oldindex >= 0 then185 if list[P.oldindex+1] ~= nil then186 local item = list[P.oldindex+1]187 local oldChild = item["button"]188 oldChild:setProperty("NormalImageRightEdge", string.sub(oldChild:getProperty("NormalImageRightEdge"),1,-10) .. "Normal")189 oldChild:setProperty("NormalImageLeftEdge", string.sub(oldChild:getProperty("NormalImageLeftEdge"),1,-10) .. "Normal")190 oldChild:setProperty("NormalImageBackground", string.sub(oldChild:getProperty("NormalImageBackground"),1,-10) .. "Normal")191 end192 end193 end194 195 --for every highlighted button check if index is on its position. If not, set imageproperty on "normal"196 local i = 1197 while i < (n*m) do198 if i == P.index +1 then199 i = i+1200 else201 if list[i] ~= nil then202 local item = list[i]203 local child = item["button"]204 local s = child:getProperty("NormalImageRightEdge")205 if string.sub(s,string.len(s)-8,string.len(s)) == "Highlight" then206 child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-10) .. "Normal")207 child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-10) .. "Normal")208 child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-10) .. "Normal")209 end210 end211 end212 i=i+1213 end214 end215 216 --enter217 if code == "28" and P.index >= 0 then218 local item = list[P.index+1]219 local child = item["button"]220 child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-10) .. "Normal")221 child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-10) .. "Normal")222 child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-10) .. "Normal")223 224 local foo = item["function"]225 foo()226 end227 228 end229 230 --write index and oldindex on the console231 --works like buttonIteratorHelper232 function indexTester(list,code,P,n,m)233 --key down234 if code == "208" then235 if P.index < 0 then -- initial status236 P.index = 0237 P.oldindex = -1238 else239 P.oldindex = P.index240 P.index = (P.index + m) % (m*n)241 242 while list[P.index+1] == nil do243 P.oldindex = P.index244 P.index = (P.index + m) % (m*n)245 end246 end247 248 --key up249 elseif code == "200" then250 if P.index < 0 then251 P.index = 0252 P.oldindex = -1253 elseif(P.index == 0) then254 P.oldindex = P.index255 P.index = m*n-m256 257 while list[P.index+1] == nil do258 P.oldindex = P.index259 P.index = (P.index-m)%(m*n)260 end261 else262 P.oldindex = P.index263 P.index = (P.index -m) % (m*n)264 265 while list[P.index+1] == nil do266 P.oldindex = P.index267 P.index = P.index -m268 end269 end270 271 --key right272 elseif code == "205" then273 if P.index < 0 then274 P.index = 0275 P.oldindex = -1276 elseif (P.index+1) % m == 0 then -- we are at the right-end of a row277 P.oldindex = P.index278 P.index = P.index + 1 -m279 280 while list[P.index+1] == nil do281 P.oldindex = P.index282 P.index = P.index + 1283 end284 else285 P.oldindex = P.index286 P.index = P.index + 1287 288 while list[P.index+1] == nil do289 if (P.index+1) % m == 0 then -- we are at the right-end of a row290 P.oldindex = P.index291 P.index = P.index + 1-m292 293 else294 P.oldindex = P.index295 P.index = P.index + 1296 end297 end298 end299 300 --key left301 elseif code == "203" then302 if P.index < 0 then303 P.index = 0304 P.oldindex = -1305 elseif P.index % m == 0 then -- we are at the left-end of a row306 P.oldindex = P.index307 P.index = P.index +m-1308 309 while list[P.index+1] == nil do310 P.oldindex = P.index311 P.index = P.index -1312 end313 else314 P.oldindex = P.index315 P.index = P.index -1316 317 while list[P.index+1] == nil do318 if P.index % m == 0 then -- we are at the left-end of a row319 P.oldindex = P.index320 P.index = P.index -1 + m321 else322 P.oldindex = P.index323 P.index = P.index -1324 end325 end326 end327 end328 329 cout(0, P.oldindex)330 cout(0, P.index)331 332 end333 334 335 336
Note: See TracChangeset
for help on using the changeset viewer.