Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11273 was 11052, checked in by landauf, 9 years ago

merged branch presentationHS15 back to trunk

  • Property svn:eol-style set to native
File size: 3.4 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()
[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]25end
26
[10253]27function 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
35end
[10253]36
37function P.shouldDisplayButton(index)
38    local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
39    return index < size
40end
41
42function P.shouldEnableButton(index)
43    return index <= P.getIndexOfLastFinishedMission() + 1
44end
45
46function 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]60end
61
[11052]62function P.Mission1Button_clicked(e)
[10253]63    P.loadLevel(P.FindLevel(0))
[10157]64end
65
[11052]66function P.Mission2Button_clicked(e)
[10253]67    P.loadLevel(P.FindLevel(1))
[10157]68end
69
[11052]70function P.Mission3Button_clicked(e)
[10253]71    P.loadLevel(P.FindLevel(2))
[10157]72end
73
[11052]74function P.Mission4Button_clicked(e)
[10253]75    P.loadLevel(P.FindLevel(3))
[10157]76end
77
[11052]78function P.Mission5Button_clicked(e)
79    P.loadLevel(P.FindLevel(4))
80end
81
82function P.Mission6Button_clicked(e)
83    P.loadLevel(P.FindLevel(5))
84end
85
86function P.Mission7Button_clicked(e)
87    P.loadLevel(P.FindLevel(6))
88end
89
90function P.Mission8Button_clicked(e)
91    P.loadLevel(P.FindLevel(7))
92end
93
94function P.Mission9Button_clicked(e)
95    P.loadLevel(P.FindLevel(8))
96end
97
[10253]98function P.loadLevel(level)
99    orxonox.execute("startGame " .. level:getXMLFilename())
100    hideAllMenuSheets()
101end
[10157]102
[10253]103function 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]117end
118
119function P.CampaignMenuBackButton_clicked(e)
120    hideMenuSheet(P.name)
121end
122
123return P
Note: See TracBrowser for help on using the repository browser.