Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menue/data/gui/scripts/SingleplayerMenu.lua @ 8892

Last change on this file since 8892 was 8890, checked in by baermatt, 13 years ago

First steps with lua, CEGUI and the Singleplayer menu.

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1-- SingleplayerMenu.lua
2
3local P = createMenuSheet("SingleplayerMenu")
4
5P.levelList = {}
6P.itemList = {}
7
8function P.onLoad()
9    P.createLevelList(nil)
10
11    --buttons are arranged in a 1x2 matrix
12    P:setButton(1, 1, {
13            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
14            ["callback"]  = P.SingleplayerStartButton_clicked
15    })
16
17    P:setButton(1, 2, {
18            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
19            ["callback"]  = P.SingleplayerBackButton_clicked
20    })
21end
22
23function P.createLevelList(tag)
24    P.levelList = {}
25    P.itemList = {}
26    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
27    listbox:resetList()
28    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
29    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
30    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
31    local index = 0
32    local level = nil
33    while index < size do
34        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
35        if level ~= nil then
36            if tag == nil then
37                table.insert(P.levelList, level)
38            elseif level:hasTag(tag) then
39                table.insert(P.levelList, level)
40            end
41        end
42        index = index + 1
43    end
44
45    for k,v in pairs(P.levelList) do
46        local item = CEGUI.createListboxTextItem(v:getName())
47        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
48        listbox:addItem(item)
49        if v:getXMLFilename() == preselect then
50            listbox:setItemSelectState(item, true)
51        end
52        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
53        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
54    end
55end
56
57function P.SingleplayerStartButton_clicked(e)
58    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
59    local choice = listbox:getFirstSelectedItem()
60    if choice ~= nil then
61        local index = listbox:getItemIndex(choice)
62        local level = P.levelList[index+1]
63        if level ~= nil then
64            orxonox.execute("startGame " .. level:getXMLFilename())
65            hideAllMenuSheets()
66        end
67    end
68end
69
70function P.SingleplayerBackButton_clicked(e)
71    hideMenuSheet(P.name)
72end
73
74return P
75
Note: See TracBrowser for help on using the repository browser.