Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/MultiplayerMenu.lua @ 9438

Last change on this file since 9438 was 8858, checked in by landauf, 13 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
  • Property svn:eol-style set to native
File size: 4.6 KB
RevLine 
[6363]1-- MultiplayerMenu.lua
2
[6746]3local P = createMenuSheet("MultiplayerMenu")
[6363]4
[7732]5--joinMode is 1 for choice "LAN" and 2 for "Internet"
[7801]6--initial status 1
7P.joinMode = 1
[7732]8
[6746]9function P.onLoad()
[8079]10    P.multiplayerMode = "startClient"
[7689]11
[8079]12    --button are arranged in a 3x2 matrix, Join and Host buttons are in the upper left and middle, the back button in the lower right of the table
13    P:setButton(1, 1, {
[7689]14            ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"),
[8079]15            ["callback"]  = P.MultiplayerJoinButton_clicked
16    })
[7689]17
[8079]18    P:setButton(1, 2, {
[7689]19            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
[8079]20            ["callback"]  = P.MultiplayerHostButton_clicked
21    })
[7689]22
[8079]23    P:setButton(2, 3, {
[7689]24            ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"),
[8079]25            ["callback"]  = P.MultiplayerBackButton_clicked
26    })
[7163]27end
28
29function P.onShow()
[7801]30    --P.showServerList()
[7163]31
[7801]32    if P.joinMode == 1 then
33        local window = winMgr:getWindow("orxonox/MultiplayerLanButton")
34        local button = tolua.cast(window,"CEGUI::RadioButton")
35        button:setSelected(true)
36    end
37    if P.joinMode == 2 then
38        local window = winMgr:getWindow("orxonox/MultiplayerInternetButton")
39        local button = tolua.cast(window,"CEGUI::RadioButton")
40        button:setSelected(true)
41    end
[7163]42end
43
[7732]44function P.LanButton_clicked(e)
[7801]45    local we = CEGUI.toWindowEventArgs(e)
46    local button = tolua.cast(we.window,"CEGUI::RadioButton")
[7732]47    P.joinMode = 1
[7801]48    if button:isSelected() == true then
[8079]49        P.showServerList()
[7801]50    end
[7732]51end
52
53function P.InternetButton_clicked(e)
[7801]54    local we = CEGUI.toWindowEventArgs(e)
55    local button = tolua.cast(we.window,"CEGUI::RadioButton")
[7732]56    P.joinMode = 2
[7801]57    if button:isSelected() == true then
[8079]58        P.showServerList()
59    end
[7732]60end
61
[7163]62function P.MultiplayerHostButton_clicked(e)
[7689]63    showMenuSheet("HostMenu", true)
[7163]64end
65
66
[7689]67function P.MultiplayerJoinButton_clicked(e)
[7876]68    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
69    local destination = nil
[7801]70    if choice then
71        local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
[7876]72        destination = P.serverList[index][2]
[7163]73    else
[7801]74        return
[7163]75    end
[7876]76    orxonox.execute("startClient " .. destination)
[7801]77    hideAllMenuSheets()
[7163]78end
79
80function P.MultiplayerBackButton_clicked(e)
81    hideMenuSheet(P.name)
82end
83
84function P.showServerList()
[8079]85    -- LAN Discovery
86    if P.joinMode == 1 then
87        local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
88        CEGUI.toListbox(listbox):resetList()
89        local discovery = orxonox.LANDiscovery:getInstance()
90        discovery:discover()
91        P.serverList = {}
92        local index = 0
93        local servername = ""
94        local serverip = ""
95        while true do
96            servername = discovery:getServerListItemName(index)
97            if servername == "" then
98                break
99            end
100            serverip = discovery:getServerListItemIP(index)
101            if serverip == "" then
102                break
103            end
104            table.insert(P.serverList, {servername, serverip})
105            index = index + 1
106        end
107        index = 1
108        for k,v in pairs(P.serverList) do
109            local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
110            item:setID(index)
111            index = index + 1
112            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
113            CEGUI.toListbox(listbox):addItem(item)
114        end
115    -- WAN Discovery
116    elseif P.joinMode == 2 then
117        local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
118        CEGUI.toListbox(listbox):resetList()
[8858]119        local discovery = orxonox.WANDiscovery()
120        orxout("discovering." )
[8079]121        discovery:discover()
[8858]122        orxout("discovered." )
[8079]123        P.serverList = {}
124        local index = 0
125        local servername = ""
126        local serverip = ""
127        while true do
128            servername = discovery:getServerListItemName(index)
129            if servername == "" then
130                break
131            end
132            serverip = discovery:getServerListItemIP(index)
133            if serverip == "" then
134                break
135            end
136            table.insert(P.serverList, {servername, serverip})
137            index = index + 1
138        end
139        index = 1
140        for k,v in pairs(P.serverList) do
141            local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
142            item:setID(index)
143            index = index + 1
144            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
145            CEGUI.toListbox(listbox):addItem(item)
146        end
147    end
[6363]148
[7689]149end
150
[6363]151return P
152
Note: See TracBrowser for help on using the repository browser.