Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/bindermFS16/data/gui/scripts/CampaignMenu.lua @ 11191

Last change on this file since 11191 was 11191, checked in by binderm, 8 years ago

The Campaign menu now works. The levels are structured in a tree. If one goes the left branch, the right one can't be taken anymore. The last challenge is to save the progress in the config variables. to set does work, but not to modify those variables.

  • Property svn:eol-style set to native
File size: 3.3 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"))
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"))
[11191]19end
[10253]20
[11052]21
[10253]22function P.updateButton(index, button)
[11186]23    local lastMission = orxonox.LevelManager:getInstance():getLastWonMission()
24    if (lastMission == "") then
25    else
26        local lastwon =P.getIndexOfLastFinishedMission()
27        orxonox.LevelManager:getInstance():updatewon(lastwon)
28    end
29
[11180]30    local test =orxonox.LevelManager:getInstance():missionactivate(index)
[11186]31
[11180]32    if (test==1) then
[10253]33        button:setProperty("Visible", "True")
[11173]34        button:setProperty("Disabled", "False")
[11180]35    elseif (test==2) then
36        button:setProperty("Visible", "True")
37        button:setProperty("Disabled", "True")
[11173]38    else
[11180]39        button:setProperty("Visible", "False")
[11173]40        button:setProperty("Disabled", "True")
[10157]41    end
42end
[10253]43
[11186]44function P.getIndexOfLastFinishedMission()
45    local lastMission = orxonox.LevelManager:getInstance():getLastWonMission()
46    if (lastMission and lastMission ~= "") then
47        local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
48        local index = 0
49        while index < size do
50            local mission = orxonox.LevelManager:getInstance():getCampaignMission(index)
51            if (mission == lastMission) then 
52                return index
53            end
54            index = index + 1
55        end
56    end
57    return -1
58end
[10157]59
[11052]60function P.Mission1Button_clicked(e)
[10253]61    P.loadLevel(P.FindLevel(0))
[10157]62end
63
[11052]64function P.Mission2Button_clicked(e)
[10253]65    P.loadLevel(P.FindLevel(1))
[10157]66end
67
[11052]68function P.Mission3Button_clicked(e)
[10253]69    P.loadLevel(P.FindLevel(2))
[10157]70end
71
[11052]72function P.Mission4Button_clicked(e)
[10253]73    P.loadLevel(P.FindLevel(3))
[10157]74end
75
[11052]76function P.Mission5Button_clicked(e)
77    P.loadLevel(P.FindLevel(4))
78end
79
80function P.Mission6Button_clicked(e)
81    P.loadLevel(P.FindLevel(5))
82end
83
84function P.Mission7Button_clicked(e)
85    P.loadLevel(P.FindLevel(6))
86end
87
88function P.Mission8Button_clicked(e)
89    P.loadLevel(P.FindLevel(7))
90end
91
92function P.Mission9Button_clicked(e)
93    P.loadLevel(P.FindLevel(8))
94end
95
[10253]96function P.loadLevel(level)
97    orxonox.execute("startGame " .. level:getXMLFilename())
98    hideAllMenuSheets()
99end
[10157]100
[10253]101function P.FindLevel(index)
102    local filename = orxonox.LevelManager:getInstance():getCampaignMission(index)
103    local level = nil
104    local templevel = nil
105    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
106    local index = 0
107    while index < size do
108        templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
109        if(templevel:getXMLFilename()==filename) then 
110            level = templevel
111        end
112    index=index+1
[10250]113    end
[10253]114    return level
[10157]115end
116
117function P.CampaignMenuBackButton_clicked(e)
118    hideMenuSheet(P.name)
119end
120
121return P
Note: See TracBrowser for help on using the repository browser.