Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7924 was 7922, checked in by landauf, 14 years ago

implemented new keyboard control of menu buttons with these new features:

  • more intuitive placement of buttons in table (row/column format instead of linear index)
  • no need to overwrite onShow() and onKeyPressed() functions, no need for P.buttonList
  • highlights the selected button in a different layout than mouse hovering
  • remembers the selection while moving through the menu hierarchy, but resets it if the menu is closed
  • allows preselected button (for example "Yes" in decision popup)
  • when opening a menu, the first selected button is not always the upper left, but instead depends on the pressed key (e.g. the 'up' key selects the button at the bottom, while the 'down' key selects the button at the top. once a button is selected, the keys behave as usual)

+ fixed wrong callback function in ingame menu

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