1 | --CampaignMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("CampaignMenu") |
---|
4 | |
---|
5 | function P:onShow() |
---|
6 | P:updateButtons() |
---|
7 | end |
---|
8 | |
---|
9 | function 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 | end |
---|
20 | |
---|
21 | |
---|
22 | function 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 |
---|
42 | end |
---|
43 | |
---|
44 | function 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 |
---|
58 | end |
---|
59 | |
---|
60 | function P.Mission1Button_clicked(e) |
---|
61 | P.loadLevel(P.FindLevel(0)) |
---|
62 | end |
---|
63 | |
---|
64 | function P.Mission2Button_clicked(e) |
---|
65 | P.loadLevel(P.FindLevel(1)) |
---|
66 | end |
---|
67 | |
---|
68 | function P.Mission3Button_clicked(e) |
---|
69 | P.loadLevel(P.FindLevel(2)) |
---|
70 | end |
---|
71 | |
---|
72 | function P.Mission4Button_clicked(e) |
---|
73 | P.loadLevel(P.FindLevel(3)) |
---|
74 | end |
---|
75 | |
---|
76 | function P.Mission5Button_clicked(e) |
---|
77 | P.loadLevel(P.FindLevel(4)) |
---|
78 | end |
---|
79 | |
---|
80 | function P.Mission6Button_clicked(e) |
---|
81 | P.loadLevel(P.FindLevel(5)) |
---|
82 | end |
---|
83 | |
---|
84 | function P.Mission7Button_clicked(e) |
---|
85 | P.loadLevel(P.FindLevel(6)) |
---|
86 | end |
---|
87 | |
---|
88 | function P.Mission8Button_clicked(e) |
---|
89 | P.loadLevel(P.FindLevel(7)) |
---|
90 | end |
---|
91 | |
---|
92 | function P.Mission9Button_clicked(e) |
---|
93 | P.loadLevel(P.FindLevel(8)) |
---|
94 | end |
---|
95 | |
---|
96 | function P.loadLevel(level) |
---|
97 | orxonox.execute("startGame " .. level:getXMLFilename()) |
---|
98 | hideAllMenuSheets() |
---|
99 | end |
---|
100 | |
---|
101 | function 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 |
---|
115 | end |
---|
116 | |
---|
117 | function P.CampaignMenuBackButton_clicked(e) |
---|
118 | hideMenuSheet(P.name) |
---|
119 | end |
---|
120 | |
---|
121 | return P |
---|