[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() |
---|
[11052] | 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")) |
---|
[10253] | 19 | |
---|
[11052] | 20 | |
---|
[10253] | 21 | if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then |
---|
| 22 | local label = winMgr:getWindow("orxonox/CampaignMenuCongratulation") |
---|
| 23 | label:setProperty("Visible","True") |
---|
[10250] | 24 | end |
---|
[10157] | 25 | end |
---|
| 26 | |
---|
[10253] | 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") |
---|
[10250] | 33 | end |
---|
[10157] | 34 | end |
---|
| 35 | end |
---|
[10253] | 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 |
---|
[10250] | 57 | end |
---|
| 58 | end |
---|
[10253] | 59 | return -1 |
---|
[10157] | 60 | end |
---|
| 61 | |
---|
[11052] | 62 | function P.Mission1Button_clicked(e) |
---|
[10253] | 63 | P.loadLevel(P.FindLevel(0)) |
---|
[10157] | 64 | end |
---|
| 65 | |
---|
[11052] | 66 | function P.Mission2Button_clicked(e) |
---|
[10253] | 67 | P.loadLevel(P.FindLevel(1)) |
---|
[10157] | 68 | end |
---|
| 69 | |
---|
[11052] | 70 | function P.Mission3Button_clicked(e) |
---|
[10253] | 71 | P.loadLevel(P.FindLevel(2)) |
---|
[10157] | 72 | end |
---|
| 73 | |
---|
[11052] | 74 | function P.Mission4Button_clicked(e) |
---|
[10253] | 75 | P.loadLevel(P.FindLevel(3)) |
---|
[10157] | 76 | end |
---|
| 77 | |
---|
[11052] | 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 | |
---|
[10253] | 98 | function P.loadLevel(level) |
---|
| 99 | orxonox.execute("startGame " .. level:getXMLFilename()) |
---|
| 100 | hideAllMenuSheets() |
---|
| 101 | end |
---|
[10157] | 102 | |
---|
[10253] | 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 |
---|
[10250] | 115 | end |
---|
[10253] | 116 | return level |
---|
[10157] | 117 | end |
---|
| 118 | |
---|
| 119 | function P.CampaignMenuBackButton_clicked(e) |
---|
| 120 | hideMenuSheet(P.name) |
---|
| 121 | end |
---|
| 122 | |
---|
| 123 | return P |
---|