Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/kicklib/data/gui/scripts/SingleplayerMenu.lua @ 8365

Last change on this file since 8365 was 7928, checked in by landauf, 14 years ago

more improvements for keyboard control of menus:

  • added setSelectionNear(r, c) function which tries to select the button closest to the given row/column
  • no initialization required anymore, the button-table grows dynamically if new buttons are inserted
  • Property svn:eol-style set to native
File size: 2.8 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()
14
15    --buttons are arranged in a 1x2 matrix
16    P:setButton(1, 1, {
17            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
18            ["callback"]  = P.SingleplayerStartButton_clicked
19    })
20
21    P:setButton(1, 2, {
22            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
23            ["callback"]  = P.SingleplayerBackButton_clicked
24    })
25end
26
27function P.createLevelList()
28    P.levelList = {}
29    P.itemList = {}
30    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
31    listbox:resetList()
32    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
33    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
34    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
35    local index = 0
36    local level = nil
37    while index < size do
38        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
39        if level ~= nil then
40            if P.showAll or not level:hasTag("test") then
41                table.insert(P.levelList, level)
42            end
43        end
44        index = index + 1
45    end
46    --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename.
47    --table.sort(levelList)
48    for k,v in pairs(P.levelList) do
49        local item = CEGUI.createListboxTextItem(v:getName())
50        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
51        listbox:addItem(item)
52        if v:getXMLFilename() == preselect then
53            listbox:setItemSelectState(item, true)
54        end
55        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
56        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
57    end
58end
59
60function P.SingleplayerStartButton_clicked(e)
61    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
62    local choice = listbox:getFirstSelectedItem()
63    if choice ~= nil then
64        local index = listbox:getItemIndex(choice)
65        local level = P.levelList[index+1]
66        if level ~= nil then
67            orxonox.execute("startGame " .. level:getXMLFilename())
68            hideAllMenuSheets()
69        end
70    end
71end
72
73function P.SingleplayerShowAll_clicked(e)
74    local checkbox = tolua.cast(winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox"), "CEGUI::Checkbox")
75    local show = checkbox:isSelected()
76    if show ~= P.showAll then
77        P.showAll = show
78        P.createLevelList()
79   end
80end
81
82function P.SingleplayerBackButton_clicked(e)
83    hideMenuSheet(P.name)
84end
85
86return P
87
Note: See TracBrowser for help on using the repository browser.