| 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/Mission1Button")) | 
|---|
| 11 | P.updateButton(1, winMgr:getWindow("orxonox/Mission2Button")) | 
|---|
| 12 | P.updateButton(2, winMgr:getWindow("orxonox/Mission3Button")) | 
|---|
| 13 | P.updateButton(3, winMgr:getWindow("orxonox/Mission4Button")) | 
|---|
| 14 | P.updateButton(4, winMgr:getWindow("orxonox/Mission5Button")) | 
|---|
| 15 | P.updateButton(5, winMgr:getWindow("orxonox/Mission6Button")) | 
|---|
| 16 | P.updateButton(6, winMgr:getWindow("orxonox/Mission7Button")) | 
|---|
| 17 | P.updateButton(7, winMgr:getWindow("orxonox/Mission8Button")) | 
|---|
| 18 | P.updateButton(8, winMgr:getWindow("orxonox/Mission9Button")) | 
|---|
| 19 |  | 
|---|
| 20 |  | 
|---|
| 21 | if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then | 
|---|
| 22 | local label = winMgr:getWindow("orxonox/CampaignMenuCongratulation") | 
|---|
| 23 | label:setProperty("Visible","True") | 
|---|
| 24 | end | 
|---|
| 25 | end | 
|---|
| 26 |  | 
|---|
| 27 | function P.updateButton(index, button) | 
|---|
| 28 | if (P.shouldDisplayButton(index)) then | 
|---|
| 29 | button:setProperty("Visible", "True") | 
|---|
| 30 |  | 
|---|
| 31 | if (P.shouldEnableButton(index)) then | 
|---|
| 32 | button:setProperty("Disabled", "False") | 
|---|
| 33 | end | 
|---|
| 34 | end | 
|---|
| 35 | end | 
|---|
| 36 |  | 
|---|
| 37 | function P.shouldDisplayButton(index) | 
|---|
| 38 | local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() | 
|---|
| 39 | return index < size | 
|---|
| 40 | end | 
|---|
| 41 |  | 
|---|
| 42 | function P.shouldEnableButton(index) | 
|---|
| 43 | return index <= P.getIndexOfLastFinishedMission() + 1 | 
|---|
| 44 | end | 
|---|
| 45 |  | 
|---|
| 46 | function P.getIndexOfLastFinishedMission() | 
|---|
| 47 | local lastMission = orxonox.LevelManager:getInstance():getLastFinishedCampaignMission() | 
|---|
| 48 | if (lastMission and lastMission ~= "") then | 
|---|
| 49 | local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() | 
|---|
| 50 | local index = 0 | 
|---|
| 51 | while index < size do | 
|---|
| 52 | local mission = orxonox.LevelManager:getInstance():getCampaignMission(index) | 
|---|
| 53 | if (mission == lastMission) then | 
|---|
| 54 | return index | 
|---|
| 55 | end | 
|---|
| 56 | index = index + 1 | 
|---|
| 57 | end | 
|---|
| 58 | end | 
|---|
| 59 | return -1 | 
|---|
| 60 | end | 
|---|
| 61 |  | 
|---|
| 62 | function P.Mission1Button_clicked(e) | 
|---|
| 63 | P.loadLevel(P.FindLevel(0)) | 
|---|
| 64 | end | 
|---|
| 65 |  | 
|---|
| 66 | function P.Mission2Button_clicked(e) | 
|---|
| 67 | P.loadLevel(P.FindLevel(1)) | 
|---|
| 68 | end | 
|---|
| 69 |  | 
|---|
| 70 | function P.Mission3Button_clicked(e) | 
|---|
| 71 | P.loadLevel(P.FindLevel(2)) | 
|---|
| 72 | end | 
|---|
| 73 |  | 
|---|
| 74 | function P.Mission4Button_clicked(e) | 
|---|
| 75 | P.loadLevel(P.FindLevel(3)) | 
|---|
| 76 | end | 
|---|
| 77 |  | 
|---|
| 78 | function P.Mission5Button_clicked(e) | 
|---|
| 79 | P.loadLevel(P.FindLevel(4)) | 
|---|
| 80 | end | 
|---|
| 81 |  | 
|---|
| 82 | function P.Mission6Button_clicked(e) | 
|---|
| 83 | P.loadLevel(P.FindLevel(5)) | 
|---|
| 84 | end | 
|---|
| 85 |  | 
|---|
| 86 | function P.Mission7Button_clicked(e) | 
|---|
| 87 | P.loadLevel(P.FindLevel(6)) | 
|---|
| 88 | end | 
|---|
| 89 |  | 
|---|
| 90 | function P.Mission8Button_clicked(e) | 
|---|
| 91 | P.loadLevel(P.FindLevel(7)) | 
|---|
| 92 | end | 
|---|
| 93 |  | 
|---|
| 94 | function P.Mission9Button_clicked(e) | 
|---|
| 95 | P.loadLevel(P.FindLevel(8)) | 
|---|
| 96 | end | 
|---|
| 97 |  | 
|---|
| 98 | function P.loadLevel(level) | 
|---|
| 99 | orxonox.execute("startGame " .. level:getXMLFilename()) | 
|---|
| 100 | hideAllMenuSheets() | 
|---|
| 101 | end | 
|---|
| 102 |  | 
|---|
| 103 | function P.FindLevel(index) | 
|---|
| 104 | local filename = orxonox.LevelManager:getInstance():getCampaignMission(index) | 
|---|
| 105 | local level = nil | 
|---|
| 106 | local templevel = nil | 
|---|
| 107 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() | 
|---|
| 108 | local index = 0 | 
|---|
| 109 | while index < size do | 
|---|
| 110 | templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) | 
|---|
| 111 | if(templevel:getXMLFilename()==filename) then | 
|---|
| 112 | level = templevel | 
|---|
| 113 | end | 
|---|
| 114 | index=index+1 | 
|---|
| 115 | end | 
|---|
| 116 | return level | 
|---|
| 117 | end | 
|---|
| 118 |  | 
|---|
| 119 | function P.CampaignMenuBackButton_clicked(e) | 
|---|
| 120 | hideMenuSheet(P.name) | 
|---|
| 121 | end | 
|---|
| 122 |  | 
|---|
| 123 | return P | 
|---|