Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menu/data/gui/scripts/HostMenu.lua @ 7687

Last change on this file since 7687 was 7687, checked in by konrad, 13 years ago

—function to iterate throgh a menusheet by using arrowkeys is added

File size: 2.8 KB
Line 
1-- HostMenu.lua
2
3local P = createMenuSheet("HostMenu")
4
5P.multiplayerMode = "startServer"
6
7P.buttonList = {}
8
9function P.onLoad()
10    P.multiplayerMode = "startClient" 
11
12    local item = {
13            ["button"] = winMgr:getWindow("orxonox/HostMenuStartButton"),
14            ["function"]  = P.HostMenuStartButton_clicked
15    }
16    P.buttonList[1] = item
17
18    local item = {
19            ["button"] = winMgr:getWindow("orxonox/HostMenuBackButton"),
20            ["function"]  = P.HostMenuBackButton_clicked
21    }
22    P.buttonList[2] = item
23end
24
25function P.onShow()
26    if P.multiplayerMode == "startServer" then
27        local window = winMgr:getWindow("orxonox/HostMenuHostButton")
28        local button = tolua.cast(window,"CEGUI::RadioButton")
29        button:setSelected(true)
30        P.showLevelList()
31    end
32
33    if P.multiplayerMode == "startDedicated" then
34        local window = winMgr:getWindow("orxonox/HostMenuDedicatedButton")
35        local button = tolua.cast(window,"CEGUI::RadioButton")
36        button:setSelected(true)
37        P.showLevelList()
38    end
39
40    P.oldindex = -2
41    P.index = -1
42
43end
44
45function P.HostMenuBuildServerButton_clicked(e)
46    P.multiplayerMode = "startServer"
47    P.showLevelList()
48end
49
50function P.HostMenuDedicatedButton_clicked(e)
51    P.multiplayerMode = "startDedicated"
52    P.showLevelList()
53end
54
55function P.HostMenuBackButton_clicked(e)
56    hideMenuSheet(P.name)
57end
58
59function P.HostMenuStartButton_clicked(e)
60    local choice = winMgr:getWindow("orxonox/HostMenuListbox"):getFirstSelectedItem()
61        if choice then
62            orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
63        else
64            return
65        end
66    orxonox.execute(P.multiplayerMode)
67    hideAllMenuSheets()
68end
69
70
71
72function P.showLevelList()
73    local listbox = winMgr:getWindow("orxonox/HostMenuListbox")
74    CEGUI.toListbox(listbox):resetList()
75    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
76    orxonox.LevelManager:getInstance():compileAvailableLevelList()
77    local levelList = {}
78    local index = 0
79    local level = ""
80    while true do
81        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
82        if level == "" then
83            break
84        end
85        table.insert(levelList, level)
86        index = index + 1
87    end
88    table.sort(levelList)
89    index = 1
90    for k,v in pairs(levelList) do
91        local item = CEGUI.createListboxTextItem(v)
92        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
93        item:setID(index)
94        index = index + 1
95        CEGUI.toListbox(listbox):addItem(item)
96        if v .. ".oxw" == preselect then
97            listbox:setItemSelectState(item, true)
98        end
99    end
100end
101
102
103function P.onKeyPressed() 
104    buttonIteratorHelper(P.buttonList, code, P, 1, 2)
105end
106
107
108
109return P
Note: See TracBrowser for help on using the repository browser.