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 | |
---|
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 |
---|
25 | end |
---|
26 | |
---|
27 | function P.updateButton(index, button) |
---|
28 | local test =orxonox.LevelManager:getInstance():missionactivate(index) |
---|
29 | if (test==1) then |
---|
30 | button:setProperty("Visible", "True") |
---|
31 | button:setProperty("Disabled", "False") |
---|
32 | elseif (test==2) then |
---|
33 | button:setProperty("Visible", "True") |
---|
34 | button:setProperty("Disabled", "True") |
---|
35 | else |
---|
36 | button:setProperty("Visible", "False") |
---|
37 | button:setProperty("Disabled", "True") |
---|
38 | end |
---|
39 | end |
---|
40 | |
---|
41 | --function P.shouldDisplayButton(index) |
---|
42 | -- local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() |
---|
43 | -- return index < size |
---|
44 | --end |
---|
45 | |
---|
46 | --function P.shouldActivateButton(index) --checks if button should be activated or not |
---|
47 | -- return index <= P.getIndexOfLastFinishedMission() + 1 |
---|
48 | --end |
---|
49 | |
---|
50 | --function P.getIndexOfLastFinishedMission() |
---|
51 | -- local lastMission = orxonox.LevelManager:getInstance():getLastFinishedCampaignMission() |
---|
52 | -- if (lastMission and lastMission ~= "") then |
---|
53 | -- local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() |
---|
54 | -- local index = 0 |
---|
55 | -- while index < size do |
---|
56 | -- local mission = orxonox.LevelManager:getInstance():getCampaignMission(index) |
---|
57 | -- if (mission == lastMission) then |
---|
58 | -- return index |
---|
59 | -- end |
---|
60 | -- index = index + 1 |
---|
61 | -- end |
---|
62 | -- end |
---|
63 | -- return -1 |
---|
64 | --end |
---|
65 | |
---|
66 | function P.Mission1Button_clicked(e) |
---|
67 | P.loadLevel(P.FindLevel(0)) |
---|
68 | end |
---|
69 | |
---|
70 | function P.Mission2Button_clicked(e) |
---|
71 | P.loadLevel(P.FindLevel(1)) |
---|
72 | end |
---|
73 | |
---|
74 | function P.Mission3Button_clicked(e) |
---|
75 | P.loadLevel(P.FindLevel(2)) |
---|
76 | end |
---|
77 | |
---|
78 | function P.Mission4Button_clicked(e) |
---|
79 | P.loadLevel(P.FindLevel(3)) |
---|
80 | end |
---|
81 | |
---|
82 | function P.Mission5Button_clicked(e) |
---|
83 | P.loadLevel(P.FindLevel(4)) |
---|
84 | end |
---|
85 | |
---|
86 | function P.Mission6Button_clicked(e) |
---|
87 | P.loadLevel(P.FindLevel(5)) |
---|
88 | end |
---|
89 | |
---|
90 | function P.Mission7Button_clicked(e) |
---|
91 | P.loadLevel(P.FindLevel(6)) |
---|
92 | end |
---|
93 | |
---|
94 | function P.Mission8Button_clicked(e) |
---|
95 | P.loadLevel(P.FindLevel(7)) |
---|
96 | end |
---|
97 | |
---|
98 | function P.Mission9Button_clicked(e) |
---|
99 | P.loadLevel(P.FindLevel(8)) |
---|
100 | end |
---|
101 | |
---|
102 | function P.loadLevel(level) |
---|
103 | orxonox.execute("startGame " .. level:getXMLFilename()) |
---|
104 | hideAllMenuSheets() |
---|
105 | end |
---|
106 | |
---|
107 | function P.FindLevel(index) |
---|
108 | local filename = orxonox.LevelManager:getInstance():getCampaignMission(index) |
---|
109 | local level = nil |
---|
110 | local templevel = nil |
---|
111 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
112 | local index = 0 |
---|
113 | while index < size do |
---|
114 | templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
115 | if(templevel:getXMLFilename()==filename) then |
---|
116 | level = templevel |
---|
117 | end |
---|
118 | index=index+1 |
---|
119 | end |
---|
120 | return level |
---|
121 | end |
---|
122 | |
---|
123 | function P.CampaignMenuBackButton_clicked(e) |
---|
124 | hideMenuSheet(P.name) |
---|
125 | end |
---|
126 | |
---|
127 | return P |
---|