[6746] | 1 | -- Returns a new menu sheet |
---|
| 2 | -- See MenuSheet.new for details about the parameters |
---|
| 3 | function createMenuSheet(name, bHidePrevious, tShowCursor, tUseKeyboard, bBlockJoyStick) |
---|
| 4 | local sheet = require("MenuSheet").new(name, bHidePrevious, tShowCursor, tUseKeyboard, bBlockJoyStick) |
---|
| 5 | _G[sheet.name] = sheet -- Global access required because of the event handlers |
---|
| 6 | return sheet |
---|
| 7 | end |
---|
| 8 | |
---|
| 9 | -- Returns a new HUD sheet |
---|
| 10 | function createHUDSheet(name) |
---|
| 11 | local sheet = require("HUDSheet").new(name) |
---|
| 12 | _G[sheet.name] = sheet -- Global access required because of the event handlers |
---|
| 13 | return sheet |
---|
| 14 | end |
---|
| 15 | |
---|
[6145] | 16 | function openDecisionPopup( text, callbackPtr ) |
---|
[6746] | 17 | showMenuSheet("DecisionPopup", false, true) |
---|
[6266] | 18 | DecisionPopup.setCallback(callbackPtr) |
---|
[6145] | 19 | DecisionPopup.setText(text) |
---|
[6266] | 20 | end |
---|
| 21 | |
---|
[6311] | 22 | function openInfoPopup(text, functionPtr, closeButton, arguments) |
---|
[6746] | 23 | showMenuSheet("InfoPopup", false, true) |
---|
[6311] | 24 | InfoPopup.execute(functionPtr, arguments) |
---|
[6266] | 25 | InfoPopup.setText(text) |
---|
[6283] | 26 | InfoPopup.setCloseButton(closeButton) |
---|
[6266] | 27 | end |
---|
[6355] | 28 | |
---|
| 29 | function getMinTextSize(window) |
---|
| 30 | local size = {} |
---|
[6387] | 31 | |
---|
[6355] | 32 | local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(window:getLookNFeel()) |
---|
| 33 | local height = window:getFont():getLineSpacing() + window:getUnclippedPixelRect():getHeight() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getHeight() |
---|
| 34 | local width = window:getFont():getTextExtent(window:getText()) + window:getUnclippedPixelRect():getWidth() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getWidth() |
---|
[6387] | 35 | |
---|
[6355] | 36 | table.insert(size, height) |
---|
| 37 | table.insert(size, width) |
---|
| 38 | return size |
---|
| 39 | end |
---|
| 40 | |
---|
| 41 | function getScrollingStepSize(window) |
---|
| 42 | local height = window:getUnclippedPixelRect():getHeight() |
---|
| 43 | local maxHeight = CEGUI.System:getSingleton():getGUISheet():getUnclippedPixelRect():getHeight() |
---|
| 44 | local ratio = height/maxHeight |
---|
| 45 | return 0.008*ratio/0.3204 |
---|
| 46 | end |
---|
[7163] | 47 | |
---|
| 48 | function getStaticTextWindowHeight(window) |
---|
| 49 | local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(window:getLookNFeel()) |
---|
| 50 | local formattedArea = lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window) |
---|
| 51 | local frameHeight = window:getUnclippedPixelRect():getHeight() - formattedArea:getHeight() |
---|
| 52 | local lines = window:getFont():getFormattedLineCount(window:getText(), formattedArea, CEGUI.WordWrapLeftAligned) |
---|
| 53 | local height = lines * window:getFont():getLineSpacing() + frameHeight |
---|
| 54 | return height |
---|
| 55 | end |
---|
[7689] | 56 | |
---|
| 57 | --function to iterate through a menu sheet by using arrowkeys |
---|
| 58 | |
---|
| 59 | --@arguments: |
---|
| 60 | -- list: 2-dimensional table, arguments are items that contain a button and its function |
---|
| 61 | -- !!note: each button can only be in the list once!! |
---|
| 62 | -- code: code of any key on the keyboard |
---|
| 63 | -- P: menusheet |
---|
| 64 | -- n: number of rows of the buttontable |
---|
| 65 | -- m: number of colums of the buttontable |
---|
| 66 | |
---|
| 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 updated |
---|
| 70 | |
---|
| 71 | --key down |
---|
| 72 | if code == "208" then |
---|
| 73 | if P.index < 0 then -- initial status |
---|
| 74 | P.index = 0 |
---|
| 75 | P.oldindex = -1 |
---|
| 76 | else |
---|
| 77 | P.oldindex = P.index |
---|
| 78 | P.index = (P.index + m) % (m*n) --modulo operation works as a "wrap around" in the button menu |
---|
| 79 | |
---|
| 80 | while list[P.index+1] == nil do |
---|
| 81 | P.oldindex = P.index |
---|
| 82 | P.index = (P.index + m) % (m*n) |
---|
| 83 | end |
---|
| 84 | end |
---|
| 85 | |
---|
| 86 | --key up |
---|
| 87 | elseif code == "200" then |
---|
| 88 | if P.index < 0 then |
---|
| 89 | P.index = 0 |
---|
| 90 | P.oldindex = -1 |
---|
| 91 | elseif(P.index == 0) then |
---|
| 92 | P.oldindex = P.index |
---|
| 93 | P.index = m*n-m |
---|
| 94 | |
---|
| 95 | while list[P.index+1] == nil do |
---|
| 96 | P.oldindex = P.index |
---|
| 97 | P.index = (P.index-m)%(m*n) |
---|
| 98 | end |
---|
| 99 | else |
---|
| 100 | P.oldindex = P.index |
---|
| 101 | P.index = (P.index -m) % (m*n) |
---|
| 102 | |
---|
| 103 | while list[P.index+1] == nil do |
---|
| 104 | P.oldindex = P.index |
---|
| 105 | P.index = (P.index-m)%(m*n) |
---|
| 106 | end |
---|
| 107 | end |
---|
| 108 | |
---|
| 109 | --key right |
---|
| 110 | elseif code == "205" then |
---|
| 111 | if P.index < 0 then |
---|
| 112 | P.index = 0 |
---|
| 113 | P.oldindex = -1 |
---|
| 114 | elseif (P.index+1) % m == 0 then -- we are at the right-end of a row |
---|
| 115 | P.oldindex = P.index |
---|
| 116 | P.index = P.index + 1 -m |
---|
| 117 | |
---|
| 118 | while list[P.index+1] == nil do |
---|
| 119 | P.oldindex = P.index |
---|
| 120 | P.index = P.index + 1 |
---|
| 121 | end |
---|
| 122 | else |
---|
| 123 | P.oldindex = P.index |
---|
| 124 | P.index = P.index + 1 |
---|
| 125 | |
---|
| 126 | while list[P.index+1] == nil do |
---|
| 127 | if (P.index+1) % m == 0 then -- we are at the right-end of a row |
---|
| 128 | P.oldindex = P.index |
---|
| 129 | P.index = P.index + 1-m |
---|
| 130 | |
---|
| 131 | else |
---|
| 132 | P.oldindex = P.index |
---|
| 133 | P.index = P.index + 1 |
---|
| 134 | end |
---|
| 135 | end |
---|
| 136 | end |
---|
| 137 | |
---|
| 138 | --key left |
---|
| 139 | elseif code == "203" then |
---|
| 140 | if P.index < 0 then |
---|
| 141 | P.index = 0 |
---|
| 142 | P.oldindex = -1 |
---|
| 143 | elseif P.index % m == 0 then -- we are at the left-end of a row |
---|
| 144 | P.oldindex = P.index |
---|
| 145 | P.index = P.index +m-1 |
---|
| 146 | |
---|
| 147 | while list[P.index+1] == nil do |
---|
| 148 | P.oldindex = P.index |
---|
| 149 | P.index = P.index -1 |
---|
| 150 | end |
---|
| 151 | else |
---|
| 152 | P.oldindex = P.index |
---|
| 153 | P.index = P.index -1 |
---|
| 154 | |
---|
| 155 | while list[P.index+1] == nil do |
---|
| 156 | if P.index % m == 0 then -- we are at the left-end of a row |
---|
| 157 | P.oldindex = P.index |
---|
| 158 | P.index = P.index -1 + m |
---|
| 159 | else |
---|
| 160 | P.oldindex = P.index |
---|
| 161 | P.index = P.index -1 |
---|
| 162 | end |
---|
| 163 | end |
---|
| 164 | end |
---|
| 165 | end |
---|
| 166 | |
---|
| 167 | --to update the new current button |
---|
| 168 | if (code == "208" or code == "200" or code == "203" or code == "205") and P.oldindex~= P.index then |
---|
| 169 | |
---|
| 170 | local system = CEGUI.System:getSingleton() |
---|
| 171 | local window = winMgr:getWindow("orxonox/MainMenuBackground") |
---|
| 172 | |
---|
| 173 | local item = list[P.index+1] |
---|
[7726] | 174 | local child = item["button"] |
---|
| 175 | local s = child:getProperty("NormalImageRightEdge") |
---|
[7689] | 176 | |
---|
| 177 | --teste ob der Button nicht schon gehighlightet ist |
---|
[7726] | 178 | if string.sub(s,string.len(s)-8,string.len(s)) == "Highlight" then |
---|
[7689] | 179 | --nop |
---|
| 180 | else |
---|
| 181 | 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 then |
---|
| 185 | if list[P.oldindex+1] ~= nil then |
---|
| 186 | 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 | end |
---|
| 192 | end |
---|
| 193 | end |
---|
| 194 | |
---|
| 195 | --for every highlighted button check if index is on its position. If not, set imageproperty on "normal" |
---|
| 196 | local i = 1 |
---|
| 197 | while i < (n*m) do |
---|
| 198 | if i == P.index +1 then |
---|
| 199 | i = i+1 |
---|
| 200 | else |
---|
| 201 | if list[i] ~= nil then |
---|
| 202 | local item = list[i] |
---|
| 203 | local child = item["button"] |
---|
[7726] | 204 | local s = child:getProperty("NormalImageRightEdge") |
---|
| 205 | if string.sub(s,string.len(s)-8,string.len(s)) == "Highlight" then |
---|
[7689] | 206 | 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 | end |
---|
| 210 | end |
---|
| 211 | end |
---|
| 212 | i=i+1 |
---|
| 213 | end |
---|
[7726] | 214 | end |
---|
| 215 | |
---|
[7689] | 216 | --enter |
---|
[7913] | 217 | if code == "28" and P.index >= 0 then |
---|
[7689] | 218 | 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 | end |
---|
| 227 | |
---|
| 228 | end |
---|
| 229 | |
---|
| 230 | --write index and oldindex on the console |
---|
| 231 | --works like buttonIteratorHelper |
---|
| 232 | function indexTester(list,code,P,n,m) |
---|
| 233 | --key down |
---|
| 234 | if code == "208" then |
---|
| 235 | if P.index < 0 then -- initial status |
---|
| 236 | P.index = 0 |
---|
| 237 | P.oldindex = -1 |
---|
| 238 | else |
---|
| 239 | P.oldindex = P.index |
---|
| 240 | P.index = (P.index + m) % (m*n) |
---|
| 241 | |
---|
| 242 | while list[P.index+1] == nil do |
---|
| 243 | P.oldindex = P.index |
---|
| 244 | P.index = (P.index + m) % (m*n) |
---|
| 245 | end |
---|
| 246 | end |
---|
| 247 | |
---|
| 248 | --key up |
---|
| 249 | elseif code == "200" then |
---|
| 250 | if P.index < 0 then |
---|
| 251 | P.index = 0 |
---|
| 252 | P.oldindex = -1 |
---|
| 253 | elseif(P.index == 0) then |
---|
| 254 | P.oldindex = P.index |
---|
| 255 | P.index = m*n-m |
---|
| 256 | |
---|
| 257 | while list[P.index+1] == nil do |
---|
| 258 | P.oldindex = P.index |
---|
| 259 | P.index = (P.index-m)%(m*n) |
---|
| 260 | end |
---|
| 261 | else |
---|
| 262 | P.oldindex = P.index |
---|
| 263 | P.index = (P.index -m) % (m*n) |
---|
| 264 | |
---|
| 265 | while list[P.index+1] == nil do |
---|
| 266 | P.oldindex = P.index |
---|
| 267 | P.index = P.index -m |
---|
| 268 | end |
---|
| 269 | end |
---|
| 270 | |
---|
| 271 | --key right |
---|
| 272 | elseif code == "205" then |
---|
| 273 | if P.index < 0 then |
---|
| 274 | P.index = 0 |
---|
| 275 | P.oldindex = -1 |
---|
| 276 | elseif (P.index+1) % m == 0 then -- we are at the right-end of a row |
---|
| 277 | P.oldindex = P.index |
---|
| 278 | P.index = P.index + 1 -m |
---|
| 279 | |
---|
| 280 | while list[P.index+1] == nil do |
---|
| 281 | P.oldindex = P.index |
---|
| 282 | P.index = P.index + 1 |
---|
| 283 | end |
---|
| 284 | else |
---|
| 285 | P.oldindex = P.index |
---|
| 286 | P.index = P.index + 1 |
---|
| 287 | |
---|
| 288 | while list[P.index+1] == nil do |
---|
| 289 | if (P.index+1) % m == 0 then -- we are at the right-end of a row |
---|
| 290 | P.oldindex = P.index |
---|
| 291 | P.index = P.index + 1-m |
---|
| 292 | |
---|
| 293 | else |
---|
| 294 | P.oldindex = P.index |
---|
| 295 | P.index = P.index + 1 |
---|
| 296 | end |
---|
| 297 | end |
---|
| 298 | end |
---|
| 299 | |
---|
| 300 | --key left |
---|
| 301 | elseif code == "203" then |
---|
| 302 | if P.index < 0 then |
---|
| 303 | P.index = 0 |
---|
| 304 | P.oldindex = -1 |
---|
| 305 | elseif P.index % m == 0 then -- we are at the left-end of a row |
---|
| 306 | P.oldindex = P.index |
---|
| 307 | P.index = P.index +m-1 |
---|
| 308 | |
---|
| 309 | while list[P.index+1] == nil do |
---|
| 310 | P.oldindex = P.index |
---|
| 311 | P.index = P.index -1 |
---|
| 312 | end |
---|
| 313 | else |
---|
| 314 | P.oldindex = P.index |
---|
| 315 | P.index = P.index -1 |
---|
| 316 | |
---|
| 317 | while list[P.index+1] == nil do |
---|
| 318 | if P.index % m == 0 then -- we are at the left-end of a row |
---|
| 319 | P.oldindex = P.index |
---|
| 320 | P.index = P.index -1 + m |
---|
| 321 | else |
---|
| 322 | P.oldindex = P.index |
---|
| 323 | P.index = P.index -1 |
---|
| 324 | end |
---|
| 325 | end |
---|
| 326 | end |
---|
| 327 | end |
---|
| 328 | |
---|
| 329 | cout(0, P.oldindex) |
---|
| 330 | cout(0, P.index) |
---|
| 331 | |
---|
| 332 | end |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | |
---|
| 336 | |
---|