[6363] | 1 | -- SingleplayerMenu.lua |
---|
| 2 | |
---|
[6746] | 3 | local P = createMenuSheet("SingleplayerMenu") |
---|
[6363] | 4 | |
---|
[7687] | 5 | P.buttonList = {} |
---|
| 6 | |
---|
[6746] | 7 | function P.onLoad() |
---|
[6363] | 8 | listbox = winMgr:getWindow("orxonox/SingleplayerLevelListbox") |
---|
| 9 | preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
| 10 | orxonox.LevelManager:getInstance():compileAvailableLevelList() |
---|
| 11 | local levelList = {} |
---|
| 12 | local index = 0 |
---|
| 13 | local level = "" |
---|
| 14 | while true do |
---|
| 15 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
| 16 | if level == "" then |
---|
| 17 | break |
---|
| 18 | end |
---|
| 19 | table.insert(levelList, level) |
---|
| 20 | index = index + 1 |
---|
| 21 | end |
---|
| 22 | table.sort(levelList) |
---|
| 23 | for k,v in pairs(levelList) do |
---|
[6388] | 24 | item = CEGUI.createListboxTextItem(v) |
---|
[6746] | 25 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
[6363] | 26 | CEGUI.toListbox(listbox):addItem(item) |
---|
| 27 | if v .. ".oxw" == preselect then |
---|
| 28 | listbox:setItemSelectState(item, true) |
---|
| 29 | end |
---|
| 30 | end |
---|
[7163] | 31 | |
---|
[7687] | 32 | --buttons are arranged in a 1x2 matrix |
---|
| 33 | local item = { |
---|
| 34 | ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"), |
---|
| 35 | ["function"] = P.SingleplayerStartButton_clicked |
---|
| 36 | } |
---|
| 37 | P.buttonList[1] = item |
---|
| 38 | |
---|
| 39 | local item = { |
---|
| 40 | ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"), |
---|
| 41 | ["function"] = P.SingleplayerBackButton_clicked |
---|
| 42 | } |
---|
| 43 | P.buttonList[2] = item |
---|
| 44 | |
---|
[6363] | 45 | end |
---|
| 46 | |
---|
[7687] | 47 | function P.onShow() |
---|
| 48 | --indices to iterate through buttonlist |
---|
| 49 | P.oldindex = -2 |
---|
| 50 | P.index = -1 |
---|
| 51 | end |
---|
| 52 | |
---|
[6363] | 53 | function P.SingleplayerStartButton_clicked(e) |
---|
[6754] | 54 | local choice = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")):getFirstSelectedItem() |
---|
[6363] | 55 | if choice then |
---|
| 56 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
[6403] | 57 | orxonox.execute("startGame") |
---|
[6746] | 58 | hideAllMenuSheets() |
---|
[6363] | 59 | end |
---|
| 60 | end |
---|
| 61 | |
---|
| 62 | function P.SingleplayerBackButton_clicked(e) |
---|
[6746] | 63 | hideMenuSheet(P.name) |
---|
[6363] | 64 | end |
---|
| 65 | |
---|
[7687] | 66 | function P.onKeyPressed() |
---|
| 67 | buttonIteratorHelper(P.buttonList, code, P, 1, 2) |
---|
| 68 | end |
---|
| 69 | |
---|
[6363] | 70 | return P |
---|
| 71 | |
---|