Пример #1
0
void EC_Sound::PlaySound()
{
    triggerSound_.Set(false, AttributeChange::LocalOnly);
    ComponentChanged(AttributeChange::LocalOnly);

    Foundation::SoundServiceInterface *soundService = framework_->GetService<Foundation::SoundServiceInterface>();
    if(!soundService)
        return;

    if(sound_id_)
        StopSound();

    OgreRenderer::EC_OgrePlaceable *placeable = dynamic_cast<OgreRenderer::EC_OgrePlaceable *>(FindPlaceable().get());
    if(placeable)
    {
        sound_id_ = soundService->PlaySound3D(soundId_.Get().toStdString(), Foundation::SoundServiceInterface::Triggered, false, placeable->GetPosition());
        soundService->SetGain(sound_id_, soundGain_.Get());
        soundService->SetLooped(sound_id_, loopSound_.Get());
        soundService->SetRange(sound_id_, soundInnerRadius_.Get(), soundOuterRadius_.Get(), 2.0f);
    }
    else // If entity isn't holding placeable component treat sound as ambient sound.
    {
        sound_id_ = soundService->PlaySound(soundId_.Get().toStdString(), Foundation::SoundServiceInterface::Ambient);
        soundService->SetGain(sound_id_, soundGain_.Get());
    }
}
JBoolean
SCComponentMenu::SetCompIndex
	(
	const JIndex compIndex
	)
{
	JIndex menuIndex;
	if (CompIndexToMenuIndex(compIndex, &menuIndex))
		{
		itsMenuIndex = menuIndex;
		SetPopupChoice(itsMenuIndex);
		if (itsBroadcastCompChangeFlag)
			{
			Broadcast(ComponentChanged(compIndex));
			}
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
void
SCComponentMenu::Receive
	(
	JBroadcaster*	sender,
	const Message&	message
	)
{
	JBroadcaster* compList = itsCircuit->GetComponentList();	// insure that it isn't const

	if (sender == this && message.Is(JXMenu::kNeedsUpdate))
		{
		itsBroadcastCompChangeFlag = kJFalse;
		Broadcast(ComponentNeedsUpdate());
		CheckItem(itsMenuIndex);
		itsBroadcastCompChangeFlag = kJTrue;
		}
	else if (sender == this && message.Is(JXMenu::kItemSelected))
		{
		const JXMenu::ItemSelected* selection =
			dynamic_cast<const JXMenu::ItemSelected*>(&message);
		assert( selection != NULL );
		itsMenuIndex = selection->GetIndex();

		JIndex compIndex;
		const JBoolean ok = MenuIndexToCompIndex(itsMenuIndex, &compIndex);
		assert( ok );
		Broadcast(ComponentChanged(compIndex));
		}

	else if (sender == compList)
		{
		JIndex compIndex;
		const JBoolean ok = MenuIndexToCompIndex(itsMenuIndex, &compIndex);
		BuildCompList();

		if (!ok)
			{
			itsMenuIndex = 1;
			}
		else if (message.Is(JOrderedSetT::kElementsInserted))
			{
			const JOrderedSetT::ElementsInserted* info =
				dynamic_cast<const JOrderedSetT::ElementsInserted*>(&message);
			assert( info != NULL && info->GetCount() == 1 );
			info->AdjustIndex(&compIndex);
			const JBoolean ok = CompIndexToMenuIndex(compIndex, &itsMenuIndex);
			assert( ok );
			}
		else if (message.Is(JOrderedSetT::kElementsRemoved))
			{
			const JOrderedSetT::ElementsRemoved* info =
				dynamic_cast<const JOrderedSetT::ElementsRemoved*>(&message);
			assert( info != NULL && info->GetCount() == 1 );
			if (info->AdjustIndex(&compIndex))
				{
				const JBoolean ok = CompIndexToMenuIndex(compIndex, &itsMenuIndex);
				assert( ok );
				}
			else
				{
				itsMenuIndex = 1;
				}
			}
		else if (message.Is(JOrderedSetT::kElementMoved))
			{
			const JOrderedSetT::ElementMoved* info =
				dynamic_cast<const JOrderedSetT::ElementMoved*>(&message);
			assert( info != NULL );
			info->AdjustIndex(&compIndex);
			const JBoolean ok = CompIndexToMenuIndex(compIndex, &itsMenuIndex);
			assert( ok );
			}
		else if (message.Is(JOrderedSetT::kElementsSwapped))
			{
			const JOrderedSetT::ElementsSwapped* info =
				dynamic_cast<const JOrderedSetT::ElementsSwapped*>(&message);
			assert( info != NULL );
			info->AdjustIndex(&compIndex);
			const JBoolean ok = CompIndexToMenuIndex(compIndex, &itsMenuIndex);
			assert( ok );
			}
		else if (message.Is(JOrderedSetT::kSorted))
			{
			assert( 0 );
			}
		// nothing extra required for JOrderedSetT::kElementChanged

		const JIndex savedIndex = itsMenuIndex;
		BuildMenu();
		itsMenuIndex = savedIndex;
		if (itsCompList->IndexValid(itsMenuIndex))
			{
			SetPopupChoice(itsMenuIndex);
			}
		}

	else
		{
		JXTextMenu::Receive(sender, message);
		}
}