Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/CampaignMenu.lua @ 10336

Last change on this file since 10336 was 10262, checked in by landauf, 10 years ago

eol-style native. no changes in code.

  • Property svn:eol-style set to native
File size: 2.7 KB
RevLine 
[10157]1--CampaignMenu.lua
2
3local P = createMenuSheet("CampaignMenu")
4
[10253]5function P:onShow()
6    P:updateButtons()
[10157]7end
8
[10253]9function 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")
[10250]18    end
[10157]19end
20
[10253]21function 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")
[10250]27        end
[10157]28    end
29end
[10253]30
31function P.shouldDisplayButton(index)
32    local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
33    return index < size
34end
35
36function P.shouldEnableButton(index)
37    return index <= P.getIndexOfLastFinishedMission() + 1
38end
39
40function 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
[10250]51        end
52    end
[10253]53    return -1
[10157]54end
55
56function P.MissionOneButton_clicked(e)
[10253]57    P.loadLevel(P.FindLevel(0))
[10157]58end
59
60function P.MissionTwoButton_clicked(e)
[10253]61    P.loadLevel(P.FindLevel(1))
[10157]62end
63
64function P.MissionThreeButton_clicked(e)
[10253]65    P.loadLevel(P.FindLevel(2))
[10157]66end
67
68function P.MissionFourButton_clicked(e)
[10253]69    P.loadLevel(P.FindLevel(3))
[10157]70end
71
[10253]72function P.loadLevel(level)
73    orxonox.execute("startGame " .. level:getXMLFilename())
74    hideAllMenuSheets()
75end
[10157]76
[10253]77function 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
[10250]89    end
[10253]90    return level
[10157]91end
92
93function P.CampaignMenuBackButton_clicked(e)
94    hideMenuSheet(P.name)
95end
96
97return P
Note: See TracBrowser for help on using the repository browser.