Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutoriallevel/data/gui/scripts/SingleplayerMenu.lua @ 8474

Last change on this file since 8474 was 7830, checked in by dafrick, 14 years ago

New implementation of QuestGUI. Should be much more usable now, however there still remain some adjustments to be made.

  • Property svn:eol-style set to native
File size: 3.0 KB
RevLine 
[6363]1-- SingleplayerMenu.lua
2
[6746]3local P = createMenuSheet("SingleplayerMenu")
[6363]4
[7689]5P.buttonList = {}
[7648]6P.levelList = {}
7P.itemList = {}
8P.showAll = false
9
[6746]10function P.onLoad()
[7648]11    local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox")
12    local button = tolua.cast(window,"CEGUI::Checkbox")
13    button:setSelected(false)
14    P.createLevelList()
[7689]15
16    --buttons are arranged in a 1x2 matrix
17    local item = {
18            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
19            ["function"]  = P.SingleplayerStartButton_clicked
20    }
21    P.buttonList[1] = item
22
23    local item = {
24            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
25            ["function"]  = P.SingleplayerBackButton_clicked
26    }
27    P.buttonList[2] = item
[7648]28end
29
30function P.createLevelList()
31    P.levelList = {}
32    P.itemList = {}
33    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
34    listbox:resetList()
35    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
36    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
37    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
[6363]38    local index = 0
[7648]39    local level = nil
40    while index < size do
41        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
42        if level ~= nil then
43            if P.showAll or not level:hasTag("test") then
44                table.insert(P.levelList, level)
45            end
46        end
47        index = index + 1
[6363]48    end
[7830]49
[7648]50    for k,v in pairs(P.levelList) do
51        local item = CEGUI.createListboxTextItem(v:getName())
[6746]52        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
[7648]53        listbox:addItem(item)
54        if v:getXMLFilename() == preselect then
[6363]55            listbox:setItemSelectState(item, true)
56        end
[7648]57        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
58        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
[6363]59    end
60end
61
[7689]62function P.onShow()
63    --indices to iterate through buttonlist
64    P.oldindex = -2
65    P.index = -1
66end
67
[6363]68function P.SingleplayerStartButton_clicked(e)
[7648]69    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
70    local choice = listbox:getFirstSelectedItem()
71    if choice ~= nil then
72        local index = listbox:getItemIndex(choice)
73        local level = P.levelList[index+1]
74        if level ~= nil then
75            orxonox.LevelManager:getInstance():setDefaultLevel(level:getXMLFilename())
76            orxonox.execute("startGame")
77            hideAllMenuSheets()
78        end
[6363]79    end
80end
81
[7648]82function P.SingleplayerShowAll_clicked(e)
83    local checkbox = tolua.cast(winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox"), "CEGUI::Checkbox")
84    local show = checkbox:isSelected()
85    if show ~= P.showAll then
86        P.showAll = show
87        P.createLevelList()
88   end
89end
90
[6363]91function P.SingleplayerBackButton_clicked(e)
[6746]92    hideMenuSheet(P.name)
[6363]93end
94
[7689]95function P.onKeyPressed() 
96    buttonIteratorHelper(P.buttonList, code, P, 1, 2)
97end
98
[6363]99return P
100
Note: See TracBrowser for help on using the repository browser.