Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/WorldMap_HS18/data/gui/scripts/CampaignMenu.lua @ 12240

Last change on this file since 12240 was 12106, checked in by linggj, 6 years ago

Story Mode Controller added again as a controllabel entitz

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1--CampaignMenu.lua
2
3local P = createMenuSheet("CampaignMenu")
4
5
6function P:onShow()
7    P:updateButtons()
8end
9
10function 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
35end
36--Updated Buttons der levels
37function 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
47end
48
49function P.Test(e)
50     orxonox.execute("startMainMenu")
51end
52
53function P.shouldDisplayButton(index)
54    local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
55    return index < size
56end
57
58function P.shouldEnableButton(index)
59    return index <= P.getIndexOfLastFinishedMission() + 1
60end
61
62function 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
76end
77
78
79
80
81function P.Mission1Button_clicked(e)
82    P.loadLevel(P.FindLevel(0))
83end
84function P.KeyPressed(e)
85    P.loadLevel(P.FindLevel(0))
86end
87
88function P.Mission2Button_clicked(e)
89    P.loadLevel(P.FindLevel(1))
90end
91
92function P.Mission3Button_clicked(e)
93    P.loadLevel(P.FindLevel(2))
94end
95
96function P.Mission4Button_clicked(e)
97    P.loadLevel(P.FindLevel(3))
98end
99
100function P.Mission5Button_clicked(e)
101    P.loadLevel(P.FindLevel(4))
102end
103
104function P.Mission6Button_clicked(e)
105    P.loadLevel(P.FindLevel(5))
106end
107
108function P.Mission7Button_clicked(e)
109    P.loadLevel(P.FindLevel(6))
110end
111
112function P.Mission8Button_clicked(e)
113    P.loadLevel(P.FindLevel(7))
114end
115
116function P.Mission9Button_clicked(e)
117    P.loadLevel(P.FindLevel(8))
118end
119
120function P.loadLevel(level)
121    orxonox.execute("changeGame " .. level:getXMLFilename())
122    hideAllMenuSheets()
123end
124
125function P.loadMap()
126    orxonox.execute("changeGame  dynamicMatch.oxw")
127     hideAllMenuSheets()
128end
129
130function 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
144end
145
146function P.CampaignMenuBackButton_clicked(e)
147    orxonox.execute("startMainMenu")
148    hideMenuSheet("CampaignMenu")
149end
150
151return P
Note: See TracBrowser for help on using the repository browser.