Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/data/gui/scripts/SingleplayerMenu.lua @ 7940

Last change on this file since 7940 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
RevLine 
[6363]1-- SingleplayerMenu.lua
2
[6746]3local P = createMenuSheet("SingleplayerMenu")
[6363]4
[7648]5P.levelList = {}
6P.itemList = {}
7P.showAll = false
8
[6746]9function P.onLoad()
[7648]10    local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox")
11    local button = tolua.cast(window,"CEGUI::Checkbox")
12    button:setSelected(false)
13    P.createLevelList()
[7689]14
15    --buttons are arranged in a 1x2 matrix
[7922]16    P:setButton(1, 1, {
[7689]17            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
[7922]18            ["callback"]  = P.SingleplayerStartButton_clicked
19    })
[7689]20
[7922]21    P:setButton(1, 2, {
[7689]22            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
[7922]23            ["callback"]  = P.SingleplayerBackButton_clicked
24    })
[7648]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()
[6363]35    local index = 0
[7648]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
[6363]45    end
[7648]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())
[6746]50        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
[7648]51        listbox:addItem(item)
52        if v:getXMLFilename() == preselect then
[6363]53            listbox:setItemSelectState(item, true)
54        end
[7648]55        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
56        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
[6363]57    end
58end
59
60function P.SingleplayerStartButton_clicked(e)
[7648]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
[7876]67            orxonox.execute("startGame " .. level:getXMLFilename())
[7648]68            hideAllMenuSheets()
69        end
[6363]70    end
71end
72
[7648]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
[6363]82function P.SingleplayerBackButton_clicked(e)
[6746]83    hideMenuSheet(P.name)
[6363]84end
85
86return P
87
Note: See TracBrowser for help on using the repository browser.