Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11503 was 11359, checked in by patricwi, 8 years ago

story mode map merged

  • Property svn:eol-style set to native
File size: 4.0 KB
RevLine 
[10157]1--CampaignMenu.lua
2
3local P = createMenuSheet("CampaignMenu")
4
[10253]5function P:onShow()
6    P:updateButtons()
[10157]7end
8
[10253]9function P.updateButtons()
[11052]10    P.updateButton(0, winMgr:getWindow("orxonox/Mission1Button"))
[11359]11    P.updateButton(0, winMgr:getWindow("orxonox/Mission1Text"))
[11052]12    P.updateButton(1, winMgr:getWindow("orxonox/Mission2Button"))
[11359]13    P.updateButton(1, winMgr:getWindow("orxonox/Mission2Text"))
[11052]14    P.updateButton(2, winMgr:getWindow("orxonox/Mission3Button"))
[11359]15    P.updateButton(2, winMgr:getWindow("orxonox/Mission3Text"))
[11052]16    P.updateButton(3, winMgr:getWindow("orxonox/Mission4Button"))
[11359]17    P.updateButton(3, winMgr:getWindow("orxonox/Mission4Text"))
[11052]18    P.updateButton(4, winMgr:getWindow("orxonox/Mission5Button"))
[11359]19    P.updateButton(4, winMgr:getWindow("orxonox/Mission5Text"))
[11052]20    P.updateButton(5, winMgr:getWindow("orxonox/Mission6Button"))
[11359]21    P.updateButton(5, winMgr:getWindow("orxonox/Mission6Text"))
[11052]22    P.updateButton(6, winMgr:getWindow("orxonox/Mission7Button"))
[11359]23    P.updateButton(6, winMgr:getWindow("orxonox/Mission7Text"))
[11052]24    P.updateButton(7, winMgr:getWindow("orxonox/Mission8Button"))
[11359]25    P.updateButton(7, winMgr:getWindow("orxonox/Mission8Text"))
[11052]26    P.updateButton(8, winMgr:getWindow("orxonox/Mission9Button"))
[11359]27    P.updateButton(8, winMgr:getWindow("orxonox/Mission9Text"))
[10253]28
[11052]29
[10253]30    if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then
31        local label = winMgr:getWindow("orxonox/CampaignMenuCongratulation")
32        label:setProperty("Visible","True")
[10250]33    end
[10157]34end
35
[10253]36function 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")
[10250]42        end
[10157]43    end
44end
[10253]45
46function P.shouldDisplayButton(index)
47    local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
48    return index < size
49end
50
51function P.shouldEnableButton(index)
52    return index <= P.getIndexOfLastFinishedMission() + 1
53end
54
55function 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
[10250]66        end
67    end
[10253]68    return -1
[10157]69end
70
[11052]71function P.Mission1Button_clicked(e)
[10253]72    P.loadLevel(P.FindLevel(0))
[10157]73end
74
[11052]75function P.Mission2Button_clicked(e)
[10253]76    P.loadLevel(P.FindLevel(1))
[10157]77end
78
[11052]79function P.Mission3Button_clicked(e)
[10253]80    P.loadLevel(P.FindLevel(2))
[10157]81end
82
[11052]83function P.Mission4Button_clicked(e)
[10253]84    P.loadLevel(P.FindLevel(3))
[10157]85end
86
[11052]87function P.Mission5Button_clicked(e)
88    P.loadLevel(P.FindLevel(4))
89end
90
91function P.Mission6Button_clicked(e)
92    P.loadLevel(P.FindLevel(5))
93end
94
95function P.Mission7Button_clicked(e)
96    P.loadLevel(P.FindLevel(6))
97end
98
99function P.Mission8Button_clicked(e)
100    P.loadLevel(P.FindLevel(7))
101end
102
103function P.Mission9Button_clicked(e)
104    P.loadLevel(P.FindLevel(8))
105end
106
[10253]107function P.loadLevel(level)
[11359]108    orxonox.execute("changeGame " .. level:getXMLFilename())
[10253]109    hideAllMenuSheets()
110end
[10157]111
[10253]112function 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
[10250]124    end
[10253]125    return level
[10157]126end
127
128function P.CampaignMenuBackButton_clicked(e)
[11359]129    orxonox.execute("startMainMenu")
130    hideMenuSheet("CampaignMenu")
[10157]131end
132
133return P
Note: See TracBrowser for help on using the repository browser.