Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/CampaignMenu.lua @ 10395

Last change on this file since 10395 was 10262, checked in by landauf, 10 years ago

eol-style native. no changes in code.

  • Property svn:eol-style set to native
File size: 2.7 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/MissionOneButton"))
11    P.updateButton(1, winMgr:getWindow("orxonox/MissionTwoButton"))
12    P.updateButton(2, winMgr:getWindow("orxonox/MissionThreeButton"))
13    P.updateButton(3, winMgr:getWindow("orxonox/MissionFourButton"))
14
15    if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then
16        local label = winMgr:getWindow("orxonox/CampaignMenuCongratulation")
17        label:setProperty("Visible","True")
18    end
19end
20
21function P.updateButton(index, button)
22    if (P.shouldDisplayButton(index)) then
23        button:setProperty("Visible", "True")
24
25        if (P.shouldEnableButton(index)) then
26            button:setProperty("Disabled", "False")
27        end
28    end
29end
30
31function P.shouldDisplayButton(index)
32    local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
33    return index < size
34end
35
36function P.shouldEnableButton(index)
37    return index <= P.getIndexOfLastFinishedMission() + 1
38end
39
40function P.getIndexOfLastFinishedMission()
41    local lastMission = orxonox.LevelManager:getInstance():getLastFinishedCampaignMission()
42    if (lastMission and lastMission ~= "") then
43        local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
44        local index = 0
45        while index < size do
46            local mission = orxonox.LevelManager:getInstance():getCampaignMission(index)
47            if (mission == lastMission) then 
48                return index
49            end
50            index = index + 1
51        end
52    end
53    return -1
54end
55
56function P.MissionOneButton_clicked(e)
57    P.loadLevel(P.FindLevel(0))
58end
59
60function P.MissionTwoButton_clicked(e)
61    P.loadLevel(P.FindLevel(1))
62end
63
64function P.MissionThreeButton_clicked(e)
65    P.loadLevel(P.FindLevel(2))
66end
67
68function P.MissionFourButton_clicked(e)
69    P.loadLevel(P.FindLevel(3))
70end
71
72function P.loadLevel(level)
73    orxonox.execute("startGame " .. level:getXMLFilename())
74    hideAllMenuSheets()
75end
76
77function P.FindLevel(index)
78    local filename = orxonox.LevelManager:getInstance():getCampaignMission(index)
79    local level = nil
80    local templevel = nil
81    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
82    local index = 0
83    while index < size do
84        templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
85        if(templevel:getXMLFilename()==filename) then 
86            level = templevel
87        end
88    index=index+1
89    end
90    return level
91end
92
93function P.CampaignMenuBackButton_clicked(e)
94    hideMenuSheet(P.name)
95end
96
97return P
Note: See TracBrowser for help on using the repository browser.