Ejemplo n.º 1
0
void CRadio::OnRadioMessage(int id, EntityId fromId)
{
	int groupId=id/RADIO_GROUP_SIZE;
	int keyId=id%RADIO_GROUP_SIZE;

	char *pSoundName,*pSoundText;
	int variations = 1;
	bool result=GetRadioSoundName(m_pGameRules,m_TeamName,groupId+1,keyId+1,&pSoundName,&pSoundText, &variations);

	assert(result);

	if(g_pGame->GetGameRules())
	{		
/*
		ILocalizationManager *pLocalizationMan = gEnv->pSystem->GetLocalizationManager();
		
		wstring completeMsg;
		wstring wRadio, wSoundText;
		pLocalizationMan->LocalizeString("@mp_radio", wRadio);
		pLocalizationMan->LocalizeString(pSoundText, wSoundText);

		IEntity* pEntity = gEnv->pEntitySystem->GetEntity(fromId);
		if(pEntity)
		{
			Vec2i grid=CHUD::Get()->GetRadar()->GetMapGridPosition(pEntity);
			completeMsg += L"(";
			completeMsg += wRadio;
			completeMsg += L", ";
			wchar_t letter = 'A' + grid.x - 1;
			wchar_t number = '0' + grid.y;
			completeMsg += letter;
			completeMsg += number;
			completeMsg += L"): ";
		}
		completeMsg += wSoundText;


		//pLocalizationMan->FormatStringMessage(localizedString, completeMsg, "@mp_radio", pSoundText);

		CHUDTextChat* pChat = CHUD::Get()->GetMPChat();
		if(pChat)
			pChat->AddChatMessage(fromId, completeMsg.c_str(), 1, true);	// hardcoded to 'same team'
		//g_pGame->GetGameRules()->OnChatMessage(eChatToTeam, fromId, 0, completeMsg.c_str());

		string sound = pSoundName;
		if(variations > 1)
		{
			int rand = Random(variations);
			sound += string().Format("_0%1d", rand+1);
		}

		PlayVoice(sound.c_str());
*/

	}
}
Ejemplo n.º 2
0
bool CRadio::OnInputEvent( const SInputEvent &event )
{
	if (event.deviceId != eDI_Keyboard)
	{
		return false;
	}

	if (!gEnv->bMultiplayer)
	{
		return false;
	}

	//CryLogAlways("RADIO: Input[%3.2f] %s %d", gEnv->pTimer->GetCurrTime(), event.keyName.c_str(), event.state);
	// Signal that input events have been processed and sent to all listeners.
	m_waitForInputEvents = false;
	const char *sKey = event.keyName.c_str();
	// nasty check, but fastest early out
	int iKey = -1;

	if(sKey != 0 && sKey[0] && !sKey[1])
	{
		iKey = atoi(sKey);

		if(iKey == 0 && sKey[0] != '0')
		{
			iKey = -1;
		}
	}

	if(iKey == -1)
	{
		return false;
	}

	if (event.state == eIS_Released)
	{
		m_keyState[iKey] = false;
	}

	bool pressed = false;

	if ((!m_keyState[iKey]) && ((event.state == eIS_Pressed) || (event.state == eIS_Down)))
	{
		pressed = true;
		m_keyState[iKey] = true;
	}

	if(gEnv->pConsole->GetStatus())
	{
		return false;
	}

	// ignore sub keys while menu is closed.
	bool menuOpen = (m_currentGroup != -1);

	if (!menuOpen)
	{
		return false;
	}

	// ignore this key, since it was pressed before or when menu opened.
	if (m_keyIgnored[iKey])
	{
		return false;
	}

	if (!pressed)
	{
		return false;
	}

	if(!GetRadioSoundName(m_pGameRules, m_TeamName, m_currentGroup + 1, iKey))
	{
		return false;
	}

	m_keyState[iKey] = false; // release will never come, since the input event listened is unregistered.
	m_inputEventConsumedKey = true; // next pending menu update, ignore menu change, since this key was used in the sublevel.

	// reset key ignorance.
	for (int i = 0; i < 10; ++i)
	{
		m_keyIgnored[i] = false;
	}

	// prevent spamming radio messages
	m_lastMessageTime = gEnv->pTimer->GetCurrTime();
	//PlayVoice(pSoundName);
	int id = (m_currentGroup * RADIO_GROUP_SIZE + iKey) - 1;
	m_pGameRules->SendRadioMessage(gEnv->pGame->GetIGameFramework()->GetClientActor()->GetEntityId(), id);
	CancelRadio();
	m_menuOpenTime = 0.0f;
	g_pGameActions->FilterMPRadio()->Enable(false);

	if (gEnv->pInput)
	{
		gEnv->pInput->RemoveEventListener(this);
	}

	return true;
}