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(0, winMgr:getWindow("orxonox/Mission1Text")) |
---|
12 | P.updateButton(1, winMgr:getWindow("orxonox/Mission2Button")) |
---|
13 | P.updateButton(1, winMgr:getWindow("orxonox/Mission2Text")) |
---|
14 | P.updateButton(2, winMgr:getWindow("orxonox/Mission3Button")) |
---|
15 | P.updateButton(2, winMgr:getWindow("orxonox/Mission3Text")) |
---|
16 | P.updateButton(3, winMgr:getWindow("orxonox/Mission4Button")) |
---|
17 | P.updateButton(3, winMgr:getWindow("orxonox/Mission4Text")) |
---|
18 | P.updateButton(4, winMgr:getWindow("orxonox/Mission5Button")) |
---|
19 | P.updateButton(4, winMgr:getWindow("orxonox/Mission5Text")) |
---|
20 | P.updateButton(5, winMgr:getWindow("orxonox/Mission6Button")) |
---|
21 | P.updateButton(5, winMgr:getWindow("orxonox/Mission6Text")) |
---|
22 | P.updateButton(6, winMgr:getWindow("orxonox/Mission7Button")) |
---|
23 | P.updateButton(6, winMgr:getWindow("orxonox/Mission7Text")) |
---|
24 | P.updateButton(7, winMgr:getWindow("orxonox/Mission8Button")) |
---|
25 | P.updateButton(7, winMgr:getWindow("orxonox/Mission8Text")) |
---|
26 | P.updateButton(8, winMgr:getWindow("orxonox/Mission9Button")) |
---|
27 | P.updateButton(8, winMgr:getWindow("orxonox/Mission9Text")) |
---|
28 | |
---|
29 | |
---|
30 | if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then |
---|
31 | local label = winMgr:getWindow("orxonox/CampaignMenuCongratulation") |
---|
32 | label:setProperty("Visible","True") |
---|
33 | end |
---|
34 | end |
---|
35 | |
---|
36 | function P.updateButton(index, button) |
---|
37 | if (P.shouldDisplayButton(index)) then |
---|
38 | button:setProperty("Visible", "True") |
---|
39 | |
---|
40 | if (P.shouldEnableButton(index)) then |
---|
41 | button:setProperty("Disabled", "False") |
---|
42 | end |
---|
43 | end |
---|
44 | end |
---|
45 | |
---|
46 | function P.shouldDisplayButton(index) |
---|
47 | local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() |
---|
48 | return index < size |
---|
49 | end |
---|
50 | |
---|
51 | function P.shouldEnableButton(index) |
---|
52 | return index <= P.getIndexOfLastFinishedMission() + 1 |
---|
53 | end |
---|
54 | |
---|
55 | function P.getIndexOfLastFinishedMission() |
---|
56 | local lastMission = orxonox.LevelManager:getInstance():getLastFinishedCampaignMission() |
---|
57 | if (lastMission and lastMission ~= "") then |
---|
58 | local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() |
---|
59 | local index = 0 |
---|
60 | while index < size do |
---|
61 | local mission = orxonox.LevelManager:getInstance():getCampaignMission(index) |
---|
62 | if (mission == lastMission) then |
---|
63 | return index |
---|
64 | end |
---|
65 | index = index + 1 |
---|
66 | end |
---|
67 | end |
---|
68 | return -1 |
---|
69 | end |
---|
70 | |
---|
71 | function P.Mission1Button_clicked(e) |
---|
72 | P.loadLevel(P.FindLevel(0)) |
---|
73 | end |
---|
74 | |
---|
75 | function P.Mission2Button_clicked(e) |
---|
76 | P.loadLevel(P.FindLevel(1)) |
---|
77 | end |
---|
78 | |
---|
79 | function P.Mission3Button_clicked(e) |
---|
80 | P.loadLevel(P.FindLevel(2)) |
---|
81 | end |
---|
82 | |
---|
83 | function P.Mission4Button_clicked(e) |
---|
84 | P.loadLevel(P.FindLevel(3)) |
---|
85 | end |
---|
86 | |
---|
87 | function P.Mission5Button_clicked(e) |
---|
88 | P.loadLevel(P.FindLevel(4)) |
---|
89 | end |
---|
90 | |
---|
91 | function P.Mission6Button_clicked(e) |
---|
92 | P.loadLevel(P.FindLevel(5)) |
---|
93 | end |
---|
94 | |
---|
95 | function P.Mission7Button_clicked(e) |
---|
96 | P.loadLevel(P.FindLevel(6)) |
---|
97 | end |
---|
98 | |
---|
99 | function P.Mission8Button_clicked(e) |
---|
100 | P.loadLevel(P.FindLevel(7)) |
---|
101 | end |
---|
102 | |
---|
103 | function P.Mission9Button_clicked(e) |
---|
104 | P.loadLevel(P.FindLevel(8)) |
---|
105 | end |
---|
106 | |
---|
107 | function P.loadLevel(level) |
---|
108 | orxonox.execute("changeGame " .. level:getXMLFilename()) |
---|
109 | hideAllMenuSheets() |
---|
110 | end |
---|
111 | |
---|
112 | function P.FindLevel(index) |
---|
113 | local filename = orxonox.LevelManager:getInstance():getCampaignMission(index) |
---|
114 | local level = nil |
---|
115 | local templevel = nil |
---|
116 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
117 | local index = 0 |
---|
118 | while index < size do |
---|
119 | templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
120 | if(templevel:getXMLFilename()==filename) then |
---|
121 | level = templevel |
---|
122 | end |
---|
123 | index=index+1 |
---|
124 | end |
---|
125 | return level |
---|
126 | end |
---|
127 | |
---|
128 | function P.CampaignMenuBackButton_clicked(e) |
---|
129 | orxonox.execute("startMainMenu") |
---|
130 | hideMenuSheet("CampaignMenu") |
---|
131 | end |
---|
132 | |
---|
133 | return P |
---|