[10157] | 1 | --CampaignMenu.lua |
---|
| 2 | |
---|
| 3 | local P = createMenuSheet("CampaignMenu") |
---|
| 4 | |
---|
[10253] | 5 | function P:onShow() |
---|
| 6 | P:updateButtons() |
---|
[10157] | 7 | end |
---|
| 8 | |
---|
[10253] | 9 | function P.updateButtons() |
---|
| 10 | P.updateButton(0, winMgr:getWindow("orxonox/MissionOneButton")) |
---|
| 11 | P.updateButton(1, winMgr:getWindow("orxonox/MissionTwoButton")) |
---|
| 12 | P.updateButton(2, winMgr:getWindow("orxonox/MissionThreeButton")) |
---|
| 13 | P.updateButton(3, winMgr:getWindow("orxonox/MissionFourButton")) |
---|
| 14 | |
---|
| 15 | if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then |
---|
| 16 | local label = winMgr:getWindow("orxonox/CampaignMenuCongratulation") |
---|
| 17 | label:setProperty("Visible","True") |
---|
[10250] | 18 | end |
---|
[10157] | 19 | end |
---|
| 20 | |
---|
[10253] | 21 | function P.updateButton(index, button) |
---|
| 22 | if (P.shouldDisplayButton(index)) then |
---|
| 23 | button:setProperty("Visible", "True") |
---|
| 24 | |
---|
| 25 | if (P.shouldEnableButton(index)) then |
---|
| 26 | button:setProperty("Disabled", "False") |
---|
[10250] | 27 | end |
---|
[10157] | 28 | end |
---|
| 29 | end |
---|
[10253] | 30 | |
---|
| 31 | function P.shouldDisplayButton(index) |
---|
| 32 | local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() |
---|
| 33 | return index < size |
---|
| 34 | end |
---|
| 35 | |
---|
| 36 | function P.shouldEnableButton(index) |
---|
| 37 | return index <= P.getIndexOfLastFinishedMission() + 1 |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | function P.getIndexOfLastFinishedMission() |
---|
| 41 | local lastMission = orxonox.LevelManager:getInstance():getLastFinishedCampaignMission() |
---|
| 42 | if (lastMission and lastMission ~= "") then |
---|
| 43 | local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() |
---|
| 44 | local index = 0 |
---|
| 45 | while index < size do |
---|
| 46 | local mission = orxonox.LevelManager:getInstance():getCampaignMission(index) |
---|
| 47 | if (mission == lastMission) then |
---|
| 48 | return index |
---|
| 49 | end |
---|
| 50 | index = index + 1 |
---|
[10250] | 51 | end |
---|
| 52 | end |
---|
[10253] | 53 | return -1 |
---|
[10157] | 54 | end |
---|
| 55 | |
---|
| 56 | function P.MissionOneButton_clicked(e) |
---|
[10253] | 57 | P.loadLevel(P.FindLevel(0)) |
---|
[10157] | 58 | end |
---|
| 59 | |
---|
| 60 | function P.MissionTwoButton_clicked(e) |
---|
[10253] | 61 | P.loadLevel(P.FindLevel(1)) |
---|
[10157] | 62 | end |
---|
| 63 | |
---|
| 64 | function P.MissionThreeButton_clicked(e) |
---|
[10253] | 65 | P.loadLevel(P.FindLevel(2)) |
---|
[10157] | 66 | end |
---|
| 67 | |
---|
| 68 | function P.MissionFourButton_clicked(e) |
---|
[10253] | 69 | P.loadLevel(P.FindLevel(3)) |
---|
[10157] | 70 | end |
---|
| 71 | |
---|
[10253] | 72 | function P.loadLevel(level) |
---|
| 73 | orxonox.execute("startGame " .. level:getXMLFilename()) |
---|
| 74 | hideAllMenuSheets() |
---|
| 75 | end |
---|
[10157] | 76 | |
---|
[10253] | 77 | function P.FindLevel(index) |
---|
| 78 | local filename = orxonox.LevelManager:getInstance():getCampaignMission(index) |
---|
| 79 | local level = nil |
---|
| 80 | local templevel = nil |
---|
| 81 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
| 82 | local index = 0 |
---|
| 83 | while index < size do |
---|
| 84 | templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
| 85 | if(templevel:getXMLFilename()==filename) then |
---|
| 86 | level = templevel |
---|
| 87 | end |
---|
| 88 | index=index+1 |
---|
[10250] | 89 | end |
---|
[10253] | 90 | return level |
---|
[10157] | 91 | end |
---|
| 92 | |
---|
| 93 | function P.CampaignMenuBackButton_clicked(e) |
---|
| 94 | hideMenuSheet(P.name) |
---|
| 95 | end |
---|
| 96 | |
---|
| 97 | return P |
---|