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