[6363] | 1 | -- SingleplayerMenu.lua |
---|
| 2 | |
---|
[6746] | 3 | local P = createMenuSheet("SingleplayerMenu") |
---|
[6363] | 4 | |
---|
[7648] | 5 | P.levelList = {} |
---|
| 6 | P.itemList = {} |
---|
| 7 | |
---|
[6746] | 8 | function P.onLoad() |
---|
[8890] | 9 | P.createLevelList(nil) |
---|
[7689] | 10 | |
---|
| 11 | --buttons are arranged in a 1x2 matrix |
---|
[8079] | 12 | P:setButton(1, 1, { |
---|
[7689] | 13 | ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"), |
---|
[8079] | 14 | ["callback"] = P.SingleplayerStartButton_clicked |
---|
| 15 | }) |
---|
[7689] | 16 | |
---|
[8079] | 17 | P:setButton(1, 2, { |
---|
[7689] | 18 | ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"), |
---|
[8079] | 19 | ["callback"] = P.SingleplayerBackButton_clicked |
---|
| 20 | }) |
---|
[7648] | 21 | end |
---|
| 22 | |
---|
[8890] | 23 | function P.createLevelList(tag) |
---|
[7648] | 24 | P.levelList = {} |
---|
| 25 | P.itemList = {} |
---|
| 26 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")) |
---|
| 27 | listbox:resetList() |
---|
| 28 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
| 29 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
| 30 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
[6363] | 31 | local index = 0 |
---|
[7648] | 32 | local level = nil |
---|
| 33 | while index < size do |
---|
| 34 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
| 35 | if level ~= nil then |
---|
[8890] | 36 | if tag == nil then |
---|
[7648] | 37 | table.insert(P.levelList, level) |
---|
[8890] | 38 | elseif level:hasTag(tag) then |
---|
| 39 | table.insert(P.levelList, level) |
---|
[7648] | 40 | end |
---|
| 41 | end |
---|
| 42 | index = index + 1 |
---|
[6363] | 43 | end |
---|
[8706] | 44 | |
---|
[7648] | 45 | for k,v in pairs(P.levelList) do |
---|
| 46 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
[6746] | 47 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
[7648] | 48 | listbox:addItem(item) |
---|
| 49 | if v:getXMLFilename() == preselect then |
---|
[6363] | 50 | listbox:setItemSelectState(item, true) |
---|
| 51 | end |
---|
[7648] | 52 | P.itemList[k] = listbox:getListboxItemFromIndex(k-1) |
---|
| 53 | orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription()) |
---|
[6363] | 54 | end |
---|
| 55 | end |
---|
| 56 | |
---|
| 57 | function P.SingleplayerStartButton_clicked(e) |
---|
[7648] | 58 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")) |
---|
| 59 | local choice = listbox:getFirstSelectedItem() |
---|
| 60 | if choice ~= nil then |
---|
| 61 | local index = listbox:getItemIndex(choice) |
---|
| 62 | local level = P.levelList[index+1] |
---|
| 63 | if level ~= nil then |
---|
[7876] | 64 | orxonox.execute("startGame " .. level:getXMLFilename()) |
---|
[7648] | 65 | hideAllMenuSheets() |
---|
| 66 | end |
---|
[6363] | 67 | end |
---|
| 68 | end |
---|
| 69 | |
---|
| 70 | function P.SingleplayerBackButton_clicked(e) |
---|
[6746] | 71 | hideMenuSheet(P.name) |
---|
[6363] | 72 | end |
---|
| 73 | |
---|
| 74 | return P |
---|
| 75 | |
---|