Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentationFS16/data/gui/scripts/CampaignMenu.lua @ 11247

Last change on this file since 11247 was 11206, checked in by fvultier, 9 years ago

merged campain menu

  • Property svn:eol-style set to native
File size: 3.3 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"))
19end
20
21
22function P.updateButton(index, button)
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
30    local test =orxonox.LevelManager:getInstance():missionactivate(index)
31
32    if (test==1) then
33        button:setProperty("Visible", "True")
34        button:setProperty("Disabled", "False")
35    elseif (test==2) then
36        button:setProperty("Visible", "True")
37        button:setProperty("Disabled", "True")
38    else
39        button:setProperty("Visible", "False")
40        button:setProperty("Disabled", "True")
41    end
42end
43
44function 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
58end
59
60function P.Mission1Button_clicked(e)
61    P.loadLevel(P.FindLevel(0))
62end
63
64function P.Mission2Button_clicked(e)
65    P.loadLevel(P.FindLevel(1))
66end
67
68function P.Mission3Button_clicked(e)
69    P.loadLevel(P.FindLevel(2))
70end
71
72function P.Mission4Button_clicked(e)
73    P.loadLevel(P.FindLevel(3))
74end
75
76function P.Mission5Button_clicked(e)
77    P.loadLevel(P.FindLevel(4))
78end
79
80function P.Mission6Button_clicked(e)
81    P.loadLevel(P.FindLevel(5))
82end
83
84function P.Mission7Button_clicked(e)
85    P.loadLevel(P.FindLevel(6))
86end
87
88function P.Mission8Button_clicked(e)
89    P.loadLevel(P.FindLevel(7))
90end
91
92function P.Mission9Button_clicked(e)
93    P.loadLevel(P.FindLevel(8))
94end
95
96function P.loadLevel(level)
97    orxonox.execute("startGame " .. level:getXMLFilename())
98    hideAllMenuSheets()
99end
100
101function 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
113    end
114    return level
115end
116
117function P.CampaignMenuBackButton_clicked(e)
118    hideMenuSheet(P.name)
119end
120
121return P
Note: See TracBrowser for help on using the repository browser.