| 1 | --CampaignMenu.lua |
|---|
| 2 | |
|---|
| 3 | local P = createMenuSheet("CampaignMenu") |
|---|
| 4 | |
|---|
| 5 | function P:onShow() |
|---|
| 6 | P:updateButtons() |
|---|
| 7 | end |
|---|
| 8 | |
|---|
| 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") |
|---|
| 18 | end |
|---|
| 19 | end |
|---|
| 20 | |
|---|
| 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") |
|---|
| 27 | end |
|---|
| 28 | end |
|---|
| 29 | end |
|---|
| 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 |
|---|
| 51 | end |
|---|
| 52 | end |
|---|
| 53 | return -1 |
|---|
| 54 | end |
|---|
| 55 | |
|---|
| 56 | function P.MissionOneButton_clicked(e) |
|---|
| 57 | P.loadLevel(P.FindLevel(0)) |
|---|
| 58 | end |
|---|
| 59 | |
|---|
| 60 | function P.MissionTwoButton_clicked(e) |
|---|
| 61 | P.loadLevel(P.FindLevel(1)) |
|---|
| 62 | end |
|---|
| 63 | |
|---|
| 64 | function P.MissionThreeButton_clicked(e) |
|---|
| 65 | P.loadLevel(P.FindLevel(2)) |
|---|
| 66 | end |
|---|
| 67 | |
|---|
| 68 | function P.MissionFourButton_clicked(e) |
|---|
| 69 | P.loadLevel(P.FindLevel(3)) |
|---|
| 70 | end |
|---|
| 71 | |
|---|
| 72 | function P.loadLevel(level) |
|---|
| 73 | orxonox.execute("startGame " .. level:getXMLFilename()) |
|---|
| 74 | hideAllMenuSheets() |
|---|
| 75 | end |
|---|
| 76 | |
|---|
| 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 |
|---|
| 89 | end |
|---|
| 90 | return level |
|---|
| 91 | end |
|---|
| 92 | |
|---|
| 93 | function P.CampaignMenuBackButton_clicked(e) |
|---|
| 94 | hideMenuSheet(P.name) |
|---|
| 95 | end |
|---|
| 96 | |
|---|
| 97 | return P |
|---|