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
RevLine 
[6363]1-- SingleplayerMenu.lua
2
[6746]3local P = createMenuSheet("SingleplayerMenu")
[6363]4
[7648]5P.levelList = {}
6P.itemList = {}
7
[6746]8function P.onLoad()
[8890]9    P.createLevelList(nil)
[7689]10
11    --buttons are arranged in a 1x2 matrix
[8079]12    P:setButton(1, 1, {
[7689]13            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
[8079]14            ["callback"]  = P.SingleplayerStartButton_clicked
15    })
[7689]16
[8079]17    P:setButton(1, 2, {
[7689]18            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
[8079]19            ["callback"]  = P.SingleplayerBackButton_clicked
20    })
[7648]21end
22
[8890]23function P.createLevelList(tag)
[7648]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()
[6363]31    local index = 0
[7648]32    local level = nil
33    while index < size do
34        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
35        if level ~= nil then
[8890]36            if tag == nil then
[7648]37                table.insert(P.levelList, level)
[8890]38            elseif level:hasTag(tag) then
39                table.insert(P.levelList, level)
[7648]40            end
41        end
42        index = index + 1
[6363]43    end
[8706]44
[7648]45    for k,v in pairs(P.levelList) do
46        local item = CEGUI.createListboxTextItem(v:getName())
[6746]47        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
[7648]48        listbox:addItem(item)
49        if v:getXMLFilename() == preselect then
[6363]50            listbox:setItemSelectState(item, true)
51        end
[7648]52        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
53        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
[6363]54    end
55end
56
57function P.SingleplayerStartButton_clicked(e)
[7648]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
[7876]64            orxonox.execute("startGame " .. level:getXMLFilename())
[7648]65            hideAllMenuSheets()
66        end
[6363]67    end
68end
69
70function P.SingleplayerBackButton_clicked(e)
[6746]71    hideMenuSheet(P.name)
[6363]72end
73
74return P
75
Note: See TracBrowser for help on using the repository browser.