Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial6/data/gui/scripts/CampaignMenu.lua @ 11990

Last change on this file since 11990 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
Line 
1--CampaignMenu.lua
2
3local P = createMenuSheet("CampaignMenu")
4
5function P:onShow()
6    P:updateButtons()
7end
8
9function P.updateButtons()
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"))
19
20
21    if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then
22        local label = winMgr:getWindow("orxonox/CampaignMenuCongratulation")
23        label:setProperty("Visible","True")
24    end
25end
26
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")
33        end
34    end
35end
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
57        end
58    end
59    return -1
60end
61
62function P.Mission1Button_clicked(e)
63    P.loadLevel(P.FindLevel(0))
64end
65
66function P.Mission2Button_clicked(e)
67    P.loadLevel(P.FindLevel(1))
68end
69
70function P.Mission3Button_clicked(e)
71    P.loadLevel(P.FindLevel(2))
72end
73
74function P.Mission4Button_clicked(e)
75    P.loadLevel(P.FindLevel(3))
76end
77
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
98function P.loadLevel(level)
99    orxonox.execute("startGame " .. level:getXMLFilename())
100    hideAllMenuSheets()
101end
102
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
115    end
116    return level
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.