1 | --CampaignMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("CampaignMenu") |
---|
4 | |
---|
5 | |
---|
6 | function P:onShow() |
---|
7 | P:updateButtons() |
---|
8 | end |
---|
9 | |
---|
10 | function P.updateButtons() |
---|
11 | P.updateButton(0, P.window:getChild("Mission1Button")) |
---|
12 | P.updateButton(0, P.window:getChild("Mission1Text")) |
---|
13 | P.updateButton(1, P.window:getChild("Mission2Button")) |
---|
14 | P.updateButton(1, P.window:getChild("Mission2Text")) |
---|
15 | P.updateButton(2, P.window:getChild("Mission3Button")) |
---|
16 | P.updateButton(2, P.window:getChild("Mission3Text")) |
---|
17 | P.updateButton(3, P.window:getChild("Mission4Button")) |
---|
18 | P.updateButton(3, P.window:getChild("Mission4Text")) |
---|
19 | P.updateButton(4, P.window:getChild("Mission5Button")) |
---|
20 | P.updateButton(4, P.window:getChild("Mission5Text")) |
---|
21 | P.updateButton(5, P.window:getChild("Mission6Button")) |
---|
22 | P.updateButton(5, P.window:getChild("Mission6Text")) |
---|
23 | P.updateButton(6, P.window:getChild("Mission7Button")) |
---|
24 | P.updateButton(6, P.window:getChild("Mission7Text")) |
---|
25 | P.updateButton(7, P.window:getChild("Mission8Button")) |
---|
26 | P.updateButton(7, P.window:getChild("Mission8Text")) |
---|
27 | P.updateButton(8, P.window:getChild("Mission9Button")) |
---|
28 | P.updateButton(8, P.window:getChild("Mission9Text")) |
---|
29 | |
---|
30 | |
---|
31 | if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then |
---|
32 | local label = P.window:getChild("CampaignMenuCongratulation") |
---|
33 | label:setProperty("Visible","True") |
---|
34 | end |
---|
35 | end |
---|
36 | --Updated Buttons der levels |
---|
37 | function P.updateButton(index, button) |
---|
38 | --Wenn genuegend Levels vorhanden sind, wird der Butten angezeigt |
---|
39 | if (P.shouldDisplayButton(index)) then |
---|
40 | button:setProperty("Visible", "True") |
---|
41 | |
---|
42 | --wenn genuegend levels bestanden sind, wird er benutzbar |
---|
43 | if (P.shouldEnableButton(index)) then |
---|
44 | button:setProperty("Disabled", "False") |
---|
45 | end |
---|
46 | end |
---|
47 | end |
---|
48 | |
---|
49 | function P.Test(e) |
---|
50 | orxonox.execute("startMainMenu") |
---|
51 | end |
---|
52 | |
---|
53 | function P.shouldDisplayButton(index) |
---|
54 | local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() |
---|
55 | return index < size |
---|
56 | end |
---|
57 | |
---|
58 | function P.shouldEnableButton(index) |
---|
59 | return index <= P.getIndexOfLastFinishedMission() + 1 |
---|
60 | end |
---|
61 | |
---|
62 | function P.getIndexOfLastFinishedMission() |
---|
63 | local lastMission = orxonox.LevelManager:getInstance():getLastFinishedCampaignMission() |
---|
64 | if (lastMission and lastMission ~= "") then |
---|
65 | local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() |
---|
66 | local index = 0 |
---|
67 | while index < size do |
---|
68 | local mission = orxonox.LevelManager:getInstance():getCampaignMission(index) |
---|
69 | if (mission == lastMission) then |
---|
70 | return index |
---|
71 | end |
---|
72 | index = index + 1 |
---|
73 | end |
---|
74 | end |
---|
75 | return -1 |
---|
76 | end |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | function P.Mission1Button_clicked(e) |
---|
82 | P.loadLevel(P.FindLevel(0)) |
---|
83 | end |
---|
84 | function P.KeyPressed(e) |
---|
85 | P.loadLevel(P.FindLevel(0)) |
---|
86 | end |
---|
87 | |
---|
88 | function P.Mission2Button_clicked(e) |
---|
89 | P.loadLevel(P.FindLevel(1)) |
---|
90 | end |
---|
91 | |
---|
92 | function P.Mission3Button_clicked(e) |
---|
93 | P.loadLevel(P.FindLevel(2)) |
---|
94 | end |
---|
95 | |
---|
96 | function P.Mission4Button_clicked(e) |
---|
97 | P.loadLevel(P.FindLevel(3)) |
---|
98 | end |
---|
99 | |
---|
100 | function P.Mission5Button_clicked(e) |
---|
101 | P.loadLevel(P.FindLevel(4)) |
---|
102 | end |
---|
103 | |
---|
104 | function P.Mission6Button_clicked(e) |
---|
105 | P.loadLevel(P.FindLevel(5)) |
---|
106 | end |
---|
107 | |
---|
108 | function P.Mission7Button_clicked(e) |
---|
109 | P.loadLevel(P.FindLevel(6)) |
---|
110 | end |
---|
111 | |
---|
112 | function P.Mission8Button_clicked(e) |
---|
113 | P.loadLevel(P.FindLevel(7)) |
---|
114 | end |
---|
115 | |
---|
116 | function P.Mission9Button_clicked(e) |
---|
117 | P.loadLevel(P.FindLevel(8)) |
---|
118 | end |
---|
119 | |
---|
120 | function P.loadLevel(level) |
---|
121 | orxonox.execute("changeGame " .. level:getXMLFilename()) |
---|
122 | hideAllMenuSheets() |
---|
123 | end |
---|
124 | |
---|
125 | function P.loadMap() |
---|
126 | orxonox.execute("changeGame dynamicMatch.oxw") |
---|
127 | hideAllMenuSheets() |
---|
128 | end |
---|
129 | |
---|
130 | function P.FindLevel(index) |
---|
131 | local filename = orxonox.LevelManager:getInstance():getCampaignMission(index) |
---|
132 | local level = nil |
---|
133 | local templevel = nil |
---|
134 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
135 | local index = 0 |
---|
136 | while index < size do |
---|
137 | templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
138 | if(templevel:getXMLFilename()==filename) then |
---|
139 | level = templevel |
---|
140 | end |
---|
141 | index=index+1 |
---|
142 | end |
---|
143 | return level |
---|
144 | end |
---|
145 | |
---|
146 | function P.CampaignMenuBackButton_clicked(e) |
---|
147 | orxonox.execute("startMainMenu") |
---|
148 | hideMenuSheet("CampaignMenu") |
---|
149 | end |
---|
150 | |
---|
151 | return P |
---|