From 63e18ed07bcd5fde39f0aadb5e1e6c41eebc6c57 Mon Sep 17 00:00:00 2001 From: freenity Date: Sat, 22 Nov 2008 22:44:02 +0000 Subject: [PATCH] #Players list in the Multiplayer menu is now working. This was SVN commit r6510. --- .../functions_page_pregame_multiplayer.js | 20 +++++++++++-------- source/ps/GameAttributes.cpp | 19 ++++++++++++++++++ source/ps/GameAttributes.h | 1 + 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/binaries/data/mods/public/gui/test/functions_page_pregame_multiplayer.js b/binaries/data/mods/public/gui/test/functions_page_pregame_multiplayer.js index 4d561fc177..d1d6119dcb 100644 --- a/binaries/data/mods/public/gui/test/functions_page_pregame_multiplayer.js +++ b/binaries/data/mods/public/gui/test/functions_page_pregame_multiplayer.js @@ -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) diff --git a/source/ps/GameAttributes.cpp b/source/ps/GameAttributes.cpp index 3aa0769eb0..d1a49ddca5 100644 --- a/source/ps/GameAttributes.cpp +++ b/source/ps/GameAttributes.cpp @@ -274,6 +274,7 @@ void CGameAttributes::ScriptingInit() AddMethod("getOpenSlot", 0); AddProperty(L"slots", &CGameAttributes::JSI_GetPlayerSlots); + AddProperty(L"getUsedSlotsAmount", &CGameAttributes::JSI_GetUsedSlotsAmount); CJSObject::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 ::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); diff --git a/source/ps/GameAttributes.h b/source/ps/GameAttributes.h index 7cd36a5608..ec2a17e932 100644 --- a/source/ps/GameAttributes.h +++ b/source/ps/GameAttributes.h @@ -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();