Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ai/data/gui/scripts/SingleplayerMenu.lua @ 7944

Last change on this file since 7944 was 7648, checked in by dafrick, 14 years ago

Merged releasetodo, containing a new way to describe and tag levels, back to trunk.

  • Property svn:eol-style set to native
File size: 2.5 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/SingleplayerShowAllCheckbox")
11    local button = tolua.cast(window,"CEGUI::Checkbox")
12    button:setSelected(false)
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    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
22    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
23    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
24    local index = 0
25    local level = nil
26    while index < size do
27        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
28        if level ~= nil then
29            if P.showAll or not level:hasTag("test") then
30                table.insert(P.levelList, level)
31            end
32        end
33        index = index + 1
34    end
35    --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename.
36    --table.sort(levelList)
37    for k,v in pairs(P.levelList) do
38        local item = CEGUI.createListboxTextItem(v:getName())
39        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
40        listbox:addItem(item)
41        if v:getXMLFilename() == preselect then
42            listbox:setItemSelectState(item, true)
43        end
44        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
45        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
46    end
47end
48
49function P.SingleplayerStartButton_clicked(e)
50    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
51    local choice = listbox:getFirstSelectedItem()
52    if choice ~= nil then
53        local index = listbox:getItemIndex(choice)
54        local level = P.levelList[index+1]
55        if level ~= nil then
56            orxonox.LevelManager:getInstance():setDefaultLevel(level:getXMLFilename())
57            orxonox.execute("startGame")
58            hideAllMenuSheets()
59        end
60    end
61end
62
63function P.SingleplayerShowAll_clicked(e)
64    local checkbox = tolua.cast(winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox"), "CEGUI::Checkbox")
65    local show = checkbox:isSelected()
66    if show ~= P.showAll then
67        P.showAll = show
68        P.createLevelList()
69   end
70end
71
72function P.SingleplayerBackButton_clicked(e)
73    hideMenuSheet(P.name)
74end
75
76return P
77
Note: See TracBrowser for help on using the repository browser.