Changeset 7689 for code/trunk/data/gui/scripts/MultiplayerMenu.lua
- Timestamp:
- Dec 1, 2010, 3:00:19 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/menu merged: 7587-7588,7594,7607-7608,7649,7663,7670-7671,7687
- Property svn:mergeinfo changed
-
code/trunk/data/gui/scripts/MultiplayerMenu.lua
r7648 r7689 3 3 local P = createMenuSheet("MultiplayerMenu") 4 4 5 P.levelList = {} 6 P.itemList = {} 7 P.showAll = false 5 P.buttonList = {} 8 6 9 7 function P.onLoad() 10 P.multiplayerMode = "startClient" 8 P.multiplayerMode = "startClient" 9 10 --button are arranged in a 2x2 matrix, the left lower item is nil 11 local item = { 12 ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"), 13 ["function"] = P.MultiplayerJoinButton2_clicked 14 } 15 P.buttonList[1] = item 16 17 local item = { 18 ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"), 19 ["function"] = P.MultiplayerHostButton2_clicked 20 } 21 P.buttonList[2] = item 22 23 local item = { 24 ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"), 25 ["function"] = P.MultiplayerBackButton_clicked 26 } 27 P.buttonList[4] = item 28 11 29 end 12 30 13 31 function P.onShow() 14 if P.multiplayerMode == "startClient" then 15 local window = winMgr:getWindow("orxonox/MultiplayerJoinButton") 16 local button = tolua.cast(window,"CEGUI::RadioButton") 17 button:setSelected(true) 18 local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") 19 checkbox:setProperty("Disabled", "True") 20 P.showServerList() 21 end 22 if P.multiplayerMode == "startServer" then 23 local window = winMgr:getWindow("orxonox/MultiplayerHostButton") 24 local button = tolua.cast(window,"CEGUI::RadioButton") 25 button:setSelected(true) 26 local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") 27 checkbox:setProperty("Disabled", "False") 28 P.showLevelList() 29 end 30 if P.multiplayerMode == "startDedicated" then 31 local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton") 32 local button = tolua.cast(window,"CEGUI::RadioButton") 33 button:setSelected(true) 34 local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") 35 checkbox:setProperty("Disabled", "True") 36 P.showLevelList() 37 end 38 end 32 P.showServerList() 39 33 40 function P.MultiplayerJoinButton_clicked(e) 41 P.multiplayerMode = "startClient" 42 local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") 43 checkbox:setProperty("Disabled", "True") 44 P.showServerList() 34 --indices to iterate through buttonlist 35 P.oldindex = -2 36 P.index = -1 45 37 end 46 38 47 39 function P.MultiplayerHostButton_clicked(e) 48 P.multiplayerMode = "startServer" 49 local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") 50 checkbox:setProperty("Disabled", "False") 51 P.showLevelList() 40 showMenuSheet("HostMenu", true) 52 41 end 53 42 54 function P.MultiplayerDedicatedButton_clicked(e)55 P.multiplayerMode = "startDedicated"56 local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")57 checkbox:setProperty("Disabled", "True")58 P.showLevelList()59 end60 43 61 function P.MultiplayerShowAll_clicked(e) 62 local checkbox = tolua.cast(winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox"), "CEGUI::Checkbox") 63 local show = checkbox:isSelected() 64 if show ~= P.showAll then 65 P.showAll = show 66 P.createLevelList() 44 function P.MultiplayerJoinButton_clicked(e) 45 local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() 46 if choice then 47 local client = orxonox.Client:getInstance() 48 local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() 49 client:setDestination( P.serverList[index][2], 55556 ) 50 else 51 return 67 52 end 68 end 69 70 function P.MultiplayerStartButton_clicked(e) 71 local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() 72 if P.multiplayerMode == "startClient" then 73 if choice then 74 local client = orxonox.Client:getInstance() 75 local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() 76 client:setDestination( P.serverList[index][2], 55556 ) 77 else 78 return 79 end 80 else 81 if choice then 82 orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") 83 else 84 return 85 end 86 end 87 orxonox.execute(P.multiplayerMode) 53 orxonox.execute("startClient") 88 54 hideAllMenuSheets() 89 55 end … … 91 57 function P.MultiplayerBackButton_clicked(e) 92 58 hideMenuSheet(P.name) 93 end94 95 function P.showLevelList()96 P.createLevelList()97 end98 99 function P.createLevelList()100 P.levelList = {}101 P.itemList = {}102 local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/MultiplayerListbox"))103 listbox:resetList()104 orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)105 local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()106 local size = orxonox.LevelManager:getInstance():getNumberOfLevels()107 local index = 0108 local level = nil109 while index < size do110 level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)111 if level ~= nil then112 if P.showAll or not level:hasTag("test") then113 table.insert(P.levelList, level)114 end115 end116 index = index + 1117 end118 --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename.119 --table.sort(levelList)120 for k,v in pairs(P.levelList) do121 local item = CEGUI.createListboxTextItem(v:getName())122 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")123 listbox:addItem(item)124 if v:getXMLFilename() == preselect then125 listbox:setItemSelectState(item, true)126 end127 P.itemList[k] = listbox:getListboxItemFromIndex(k-1)128 orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())129 end130 59 end 131 60 … … 161 90 end 162 91 92 function P.onKeyPressed() 93 buttonIteratorHelper(P.buttonList, code, P, 2, 2) 94 end 95 163 96 return P 164 97
Note: See TracChangeset
for help on using the changeset viewer.