Пример #1
0
MenuState::MenuState( StateStack & stack, Context context ) :
	State( stack, context ),
	pImpl( new Impl )
{
	pImpl->mBackgroundSprite.setTexture( context.pTextures->Get( Texture::TitleScreen ) );

	auto playButton = std::make_shared< GUI::Button >( context );
	playButton->setPosition( 100, 300 );
	playButton->SetText( "Play" );
	playButton->SetCallback( [this] ()
	{
		RequestStackPop();
		RequestStackPush( StateID::Loading );
	});

	auto hostPlayButton = std::make_shared<GUI::Button>( context );
	hostPlayButton->setPosition( 100, 350 );
	hostPlayButton->SetText( "Host" );
	hostPlayButton->SetCallback( [this] ()
	{
		RequestStackPop();
		RequestStackPush( StateID::HostGame );
	} );

	auto joinPlayButton = std::make_shared<GUI::Button>( context );
	joinPlayButton->setPosition( 100, 400 );
	joinPlayButton->SetText( "Join" );
	joinPlayButton->SetCallback( [this] ()
	{
		RequestStackPop();
		RequestStackPush( StateID::JoinGame );
	} );

	auto settingsButton = std::make_shared< GUI::Button >( context );
	settingsButton->setPosition( 100, 450 );
	settingsButton->SetText( "Settings" );
	settingsButton->SetCallback( [this] ()
	{
		RequestStackPush( StateID::Settings );
	});

	auto exitButton = std::make_shared< GUI::Button >( context );
	exitButton->setPosition( 100, 500 );
	exitButton->SetText( "Exit" );
	exitButton->SetCallback( [this] ()
	{
		RequestStackPop();
	});

	pImpl->mGUIContainer.Pack( playButton );
	pImpl->mGUIContainer.Pack( hostPlayButton );
	pImpl->mGUIContainer.Pack( joinPlayButton );
	pImpl->mGUIContainer.Pack( settingsButton );
	pImpl->mGUIContainer.Pack( exitButton );

	// Play menu theme
	//context.pMusic->Play( Music::MenuTheme );
}
Пример #2
0
bool PauseState::HandleEvent(const sf::Event& event) {
    bool activeNextFrame = IsActive();
    
    if (activeNextFrame) {
        if (event.type == sf::Event::MouseButtonPressed
            && event.mouseButton.button == sf::Mouse::Left) {

            sf::Vector2i position = sf::Mouse::getPosition(*GetContext().window);            
            
            if (resumeButton.getGlobalBounds().contains(position.x, position.y)) {
                backwardClick->play();
                RequestStackPop();
                SetActive(false);
            } else if (restartButton.getGlobalBounds().contains(position.x, position.y)) {
                backwardClick->play();
                RequestStackClear();
                RequestStackPush(States::GAME);
                SetActive(false);
            } else if (exitButton.getGlobalBounds().contains(position.x, position.y)) {
                backwardClick->play();
                RequestStackClear();
                RequestStackPush(States::MENU);
                SetActive(false);
            }
        }
    }
    
    return activeNextFrame;
}
Пример #3
0
bool LoadingState::Update( sf::Time deltaTime )
{
	if( pImpl->mLoadingTask.IsFinished() )
	{
		RequestStackPop();
		RequestStackPush( StateID::Game );
	}
	else
	{
		pImpl->SetCompletion( pImpl->mLoadingTask.GetCompletion() );
	}

	return true;
}