Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Now we have the level description as tooltip. Unforunately for this to work i had to write two additional wrappers for CEGUI lua functions, so I guess it's time to start investigating why some CEGUI functions work in lua and some don't.

  • 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/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    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.SingleplayerShowRestrictedButton_clicked(e)
67    P.showAll = false
68    P.createLevelList()
69end
70
71function P.SingleplayerShowAllButton_clicked(e)
72    P.showAll = true
73    P.createLevelList()
74end
75
76function P.SingleplayerBackButton_clicked(e)
77    hideMenuSheet(P.name)
78end
79
80return P
81
Note: See TracBrowser for help on using the repository browser.