Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Some performance an GUI enhancement.

  • Property svn:eol-style set to native
File size: 2.6 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.
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        --TODO: The description as tooltip would be nice.
46        --local lItem = tolua.cast("CEGUI::ListboxItem", P.itemList[k])
47        --lItem:setTooltipText(v:getDescription())
48        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
49    end
50end
51
52function P.SingleplayerStartButton_clicked(e)
53    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
54    local choice = listbox:getFirstSelectedItem()
55    if choice ~= nil then
56        local index = listbox:getItemIndex(choice)
57        local level = P.levelList[index+1]
58        if level ~= nil then
59            orxonox.LevelManager:getInstance():setDefaultLevel(level:getXMLFilename())
60            orxonox.execute("startGame")
61            hideAllMenuSheets()
62        end
63    end
64end
65
66function P.SingleplayerShowAll_clicked(e)
67    local checkbox = tolua.cast(winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox"), "CEGUI::Checkbox")
68    local show = checkbox:isSelected()
69    if show ~= P.showAll then
70        P.showAll = show
71        P.createLevelList()
72   end
73end
74
75function P.SingleplayerBackButton_clicked(e)
76    hideMenuSheet(P.name)
77end
78
79return P
80
Note: See TracBrowser for help on using the repository browser.