1
0
forked from 0ad/0ad

#Players list in the Multiplayer menu is now working.

This was SVN commit r6510.
This commit is contained in:
freenity 2008-11-22 22:44:02 +00:00
parent d1fa6e8488
commit 63e18ed07b
3 changed files with 32 additions and 8 deletions

View File

@ -43,16 +43,18 @@ function initMPHost (parentWindow, gameName, welcomeMessage, profileName)
// Assign newly connected client to next available slot.
var playerSlot = g_GameAttributes.getOpenSlot();
playerSlot.assignToSession (event.session);
console.write (event.id);
// Set player slot to new player's name.
//pushItem ("pgSessionSetupP" + (event.id), event.name);
// Set player slot to new player's name
var slotID = g_GameAttributes.getUsedSlotsAmount;
pushItem ("pgSessionSetupP" + slotID, g_GameAttributes.slots[slotID-1].player.name);
}
server.onClientDisconnect = function (event)
{
// Client has disconnected; free their slot.
g_GameAttributes.slots[event.id].assignOpen();
var result = setCurrItemValue ("pgSessionSetupP" + event.id, "Open");
var slotID = g_GameAttributes.getUsedSlotsAmount-1;
g_GameAttributes.slots[slotID].assignOpen();
var result = setCurrItemValue ("pgSessionSetupP" + slotID, "Open");
messageBox(400, 200, "Client " + event.name + "(" + event.id + ") disconnected from " + event.session + ".", "Client Disconnected", 2, new Array(), new Array());
}
@ -77,9 +79,11 @@ function initMPClient (mpParentWindow, ipAddress, profileName)
client.onClientConnect = function (event)
{
// Set player slot to new player's name.
console.write("onClientConnect: name is " + event.name + ", id is " + event.id);
//if( event.id != 1 )
// pushItem ("pgSessionSetupP" + (event.id), event.name);
console.write("onClientConnect: name is " + event.name + ", event id is " + event.id);
var slotID = g_GameAttributes.getUsedSlotsAmount;
console.write("slotID="+slotID);
pushItem ("pgSessionSetupP" + eval(slotID+1), g_GameAttributes.slots[slotID].player.name);
}
client.onConnectComplete = function (event)

View File

@ -274,6 +274,7 @@ void CGameAttributes::ScriptingInit()
AddMethod<jsval_t, &CGameAttributes::JSI_GetOpenSlot>("getOpenSlot", 0);
AddProperty(L"slots", &CGameAttributes::JSI_GetPlayerSlots);
AddProperty(L"getUsedSlotsAmount", &CGameAttributes::JSI_GetUsedSlotsAmount);
CJSObject<CGameAttributes>::ScriptingInit("GameAttributes");
}
@ -289,6 +290,24 @@ jsval_t CGameAttributes::JSI_GetOpenSlot(JSContext* UNUSED(cx), uintN UNUSED(arg
return JSVAL_NULL;
}
jsval CGameAttributes::JSI_GetUsedSlotsAmount(JSContext* UNUSED(cx))
{
int i = 0;
std::vector <CPlayerSlot *>::iterator it;
for (it = m_PlayerSlots.begin();it != m_PlayerSlots.end();++it)
{
if ((*it)->GetAssignment() != SLOT_OPEN)
{
i++;
}
else
{
return INT_TO_JSVAL(i);
}
}
return INT_TO_JSVAL(i);
}
jsval CGameAttributes::JSI_GetPlayerSlots(JSContext* UNUSED(cx))
{
return OBJECT_TO_JSVAL(m_PlayerSlotArrayJS);

View File

@ -158,6 +158,7 @@ private:
jsval JSI_GetPlayerSlots(JSContext* cx);
jsval_t JSI_GetOpenSlot(JSContext *cx, uintN argc, jsval *argv);
jsval JSI_GetUsedSlotsAmount(JSContext* cx);
public:
CGameAttributes();