Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/releasetodo/data/gui/scripts/SingleplayerMenu.lua @ 7626

Last change on this file since 7626 was 7626, checked in by dafrick, 13 years ago

Accidentally removed a file. Re-adding it.
Levels that are tagged with "test" are now not displayed by default, but can be displayed by choosing show all.

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1-- SingleplayerMenu.lua
2
3local P = createMenuSheet("SingleplayerMenu")
4
5P.levelList = {}
6P.itemList = {}
7P.showAll = false
8
9function P.onLoad()
10    local window = winMgr:getWindow("orxonox/SingleplayerShowRestrictedButton")
11    local button = tolua.cast(window,"CEGUI::RadioButton")
12    button:setSelected(true)
13    P.createLevelList()
14end
15
16function P.createLevelList()
17    P.levelList = {}
18    P.itemList = {}
19    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
20    listbox:resetList()
21    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
22    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
23    local index = 0
24    local level = nil
25    while index < size do
26        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
27        if level ~= nil then
28            if P.showAll or not level:hasTag("test") then
29                table.insert(P.levelList, level)
30            end
31        end
32        index = index + 1
33    end
34    --TODO: Reintroduce sorting, if needed.
35    --table.sort(levelList)
36    for k,v in pairs(P.levelList) do
37        local item = CEGUI.createListboxTextItem(v:getName())
38        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
39        listbox:addItem(item)
40        if v:getXMLFilename() == preselect then
41            listbox:setItemSelectState(item, true)
42        end
43        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
44        --TODO: The description as tooltip would be nice.
45        --local lItem = tolua.cast("CEGUI::ListboxItem", P.itemList[k])
46        --lItem:setTooltipText(v:getDescription())
47    end
48end
49
50function P.SingleplayerStartButton_clicked(e)
51    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
52    local choice = listbox:getFirstSelectedItem()
53    if choice ~= nil then
54        local index = listbox:getItemIndex(choice)
55        local level = P.levelList[index+1]
56        if level ~= nil then
57            orxonox.LevelManager:getInstance():setDefaultLevel(level:getXMLFilename())
58            orxonox.execute("startGame")
59            hideAllMenuSheets()
60        end
61    end
62end
63
64function P.SingleplayerShowRestrictedButton_clicked(e)
65    P.showAll = false
66    P.createLevelList()
67end
68
69function P.SingleplayerShowAllButton_clicked(e)
70    P.showAll = true
71    P.createLevelList()
72end
73
74function P.SingleplayerBackButton_clicked(e)
75    hideMenuSheet(P.name)
76end
77
78return P
79
Note: See TracBrowser for help on using the repository browser.