--CampaignMenu.lua local P = createMenuSheet("CampaignMenu") function P:onShow() P:updateButtons() end function P.updateButtons() P.updateButton(0, winMgr:getWindow("orxonox/Mission1Button")) P.updateButton(1, winMgr:getWindow("orxonox/Mission2Button")) P.updateButton(2, winMgr:getWindow("orxonox/Mission3Button")) P.updateButton(3, winMgr:getWindow("orxonox/Mission4Button")) P.updateButton(4, winMgr:getWindow("orxonox/Mission5Button")) P.updateButton(5, winMgr:getWindow("orxonox/Mission6Button")) P.updateButton(6, winMgr:getWindow("orxonox/Mission7Button")) P.updateButton(7, winMgr:getWindow("orxonox/Mission8Button")) P.updateButton(8, winMgr:getWindow("orxonox/Mission9Button")) end function P.updateButton(index, button) local lastMission = orxonox.LevelManager:getInstance():getLastWonMission() if (lastMission == "") then else local lastwon =P.getIndexOfLastFinishedMission() orxonox.LevelManager:getInstance():updatewon(lastwon) end local test =orxonox.LevelManager:getInstance():missionactivate(index) if (test==1) then button:setProperty("Visible", "True") button:setProperty("Disabled", "False") elseif (test==2) then button:setProperty("Visible", "True") button:setProperty("Disabled", "True") else button:setProperty("Visible", "False") button:setProperty("Disabled", "True") end end function P.getIndexOfLastFinishedMission() local lastMission = orxonox.LevelManager:getInstance():getLastWonMission() if (lastMission and lastMission ~= "") then local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() local index = 0 while index < size do local mission = orxonox.LevelManager:getInstance():getCampaignMission(index) if (mission == lastMission) then return index end index = index + 1 end end return -1 end function P.Mission1Button_clicked(e) P.loadLevel(P.FindLevel(0)) end function P.Mission2Button_clicked(e) P.loadLevel(P.FindLevel(1)) end function P.Mission3Button_clicked(e) P.loadLevel(P.FindLevel(2)) end function P.Mission4Button_clicked(e) P.loadLevel(P.FindLevel(3)) end function P.Mission5Button_clicked(e) P.loadLevel(P.FindLevel(4)) end function P.Mission6Button_clicked(e) P.loadLevel(P.FindLevel(5)) end function P.Mission7Button_clicked(e) P.loadLevel(P.FindLevel(6)) end function P.Mission8Button_clicked(e) P.loadLevel(P.FindLevel(7)) end function P.Mission9Button_clicked(e) P.loadLevel(P.FindLevel(8)) end function P.loadLevel(level) orxonox.execute("startGame " .. level:getXMLFilename()) hideAllMenuSheets() end function P.FindLevel(index) local filename = orxonox.LevelManager:getInstance():getCampaignMission(index) local level = nil local templevel = nil local size = orxonox.LevelManager:getInstance():getNumberOfLevels() local index = 0 while index < size do templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) if(templevel:getXMLFilename()==filename) then level = templevel end index=index+1 end return level end function P.CampaignMenuBackButton_clicked(e) hideMenuSheet(P.name) end return P