MenuState::MenuState(StateStack& stack, Context context)
: State(stack, context)
, mGUIContainer()
{
	sf::Texture& texture = context.textures->get(Textures::TitleScreen);
	mBackgroundSprite.setTexture(texture);

	auto playButton = std::make_shared<GUI::Button>(context);
	playButton->setPosition(100, 300);
	playButton->setText("Play");
	playButton->setCallback([this] ()
	{
		requestStackPop();
		requestStackPush(States::Game);
	});

	auto hostPlayButton = std::make_shared<GUI::Button>(context);
	hostPlayButton->setPosition(100, 350);
	hostPlayButton->setText("Host");
	hostPlayButton->setCallback([this] ()
	{
		requestStackPop();
		requestStackPush(States::HostGame);
	});

	auto joinPlayButton = std::make_shared<GUI::Button>(context);
	joinPlayButton->setPosition(100, 400);
	joinPlayButton->setText("Join");
	joinPlayButton->setCallback([this] ()
	{
		requestStackPop();
		requestStackPush(States::JoinGame);
	});

	auto settingsButton = std::make_shared<GUI::Button>(context);
	settingsButton->setPosition(100, 450);
	settingsButton->setText("Settings");
	settingsButton->setCallback([this] ()
	{
		requestStackPush(States::Settings);
	});

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

	mGUIContainer.pack(playButton);
	mGUIContainer.pack(hostPlayButton);
	mGUIContainer.pack(joinPlayButton);
	mGUIContainer.pack(settingsButton);
	mGUIContainer.pack(exitButton);

	// Play menu theme
	context.music->play(Music::MenuTheme);
}
Esempio n. 2
0
MenuState::MenuState(trmb::StateStack& stack, trmb::State::Context context)
: trmb::State(stack, context)
, mFullscreen(0x5a0d2314)
, mWindowed(0x11e3c735)
, mGUIContainer(context.window)
{
	// ALW - Calculate x, y coordinates relative to the center of the window,
	// ALW - so GUI elements are equidistance from the center in any resolution.
	const sf::Vector2f center = sf::Vector2f(context.window->getSize() / 2u);

	sf::Texture& texture = context.textures->get(Textures::ID::TitleScreen);
	mBackgroundSprite.setTexture(texture);
	trmb::centerOrigin(mBackgroundSprite);
	mBackgroundSprite.setPosition(center);

	const float x = center.x - 375.0f;
	const float y = center.y - 100.0f;
	const float buttonHeight = 50.0f;

	mPlayButton = std::make_shared<trmb::Button>(context, Fonts::ID::Main, SoundEffects::ID::Button, Textures::ID::Buttons, 200, 50);
	mPlayButton->setPosition(x, y);
	mPlayButton->setText("Play");
	mPlayButton->setCallback([this]()
	{
		requestStackPop();
		requestStackPush(States::ID::Game);
	});

	mSettingsButton = std::make_shared<trmb::Button>(context, Fonts::ID::Main, SoundEffects::ID::Button, Textures::ID::Buttons, 200, 50);
	mSettingsButton->setPosition(x, y + buttonHeight);
	mSettingsButton->setText("Settings");
	mSettingsButton->setCallback([this]()
	{
		requestStackPush(States::ID::Settings);
	});

	mExitButton = std::make_shared<trmb::Button>(context, Fonts::ID::Main, SoundEffects::ID::Button, Textures::ID::Buttons, 200, 50);
	mExitButton->setPosition(x, y + 2.0f * buttonHeight);
	mExitButton->setText("Exit");
	mExitButton->setCallback([this]()
	{
		requestStackPop();
	});

	mGUIContainer.pack(mPlayButton);
	mGUIContainer.pack(mSettingsButton);
	mGUIContainer.pack(mExitButton);

	// Play menu theme
	context.music->play(Music::ID::MenuTheme);
}
Esempio n. 3
0
PlayState::PlayState(StateStack& stack, Context context) : State(stack, context), mGUIContainer() {
	sf::Texture& texture = context.textures->get(Textures::TitleScreen);
	mBackgroundSprite.setTexture(texture);
	sf::Vector2f windowSize(context.window->getSize());

	auto playButton = std::make_shared<GUI::Button>(context);
	playButton->setPosition(0.4f * windowSize.x, 0.3f * windowSize.y);
	playButton->setText("New Game");
	playButton->setCallback([this]() {
		requestStackPop();
		requestStackPush(States::Game);
	});

	auto LevelButton = std::make_shared<GUI::Button>(context);
	LevelButton->setPosition(0.4f * windowSize.x, 0.4f * windowSize.y);
	LevelButton->setText("Select Level");
	LevelButton->setCallback([this]() {
		requestStackPush(States::LevelSelect);
	});

	auto UpgradesButton = std::make_shared<GUI::Button>(context);
	UpgradesButton->setPosition(0.4f * windowSize.x, 0.5f * windowSize.y);
	UpgradesButton->setText("Ship Modifications");
	UpgradesButton->setCallback([this]() {
		requestStackPush(States::Upgrade);
	});

	auto LeaderBButton = std::make_shared<GUI::Button>(context);
	LeaderBButton->setPosition(0.4f * windowSize.x, 0.6f * windowSize.y);
	LeaderBButton->setText("Leaderboards");
	LeaderBButton->setCallback([this]() {
		requestStackPush(States::Leader);
	});


	auto backButton = std::make_shared<GUI::Button>(context);
	backButton->setPosition(0.4f * windowSize.x, 0.8f * windowSize.y);
	backButton->setText("Back");
	backButton->setCallback([this]() {
		requestStackPop();
		requestStackPush(States::Menu);
	});

	mGUIContainer.pack(playButton);
	mGUIContainer.pack(LevelButton);
	mGUIContainer.pack(UpgradesButton);
	mGUIContainer.pack(LeaderBButton);
	mGUIContainer.pack(backButton);
}
Esempio n. 4
0
bool TitleState::handleEvent(const sf::Event& event)
{
    /* Lazy way to completely abort this state -- we don't need it */
    requestStackPop();
    requestStackPush(States::Menu);

    // If the any key is pressed, trigger the next screen
    if (event.type == sf::Event::KeyPressed)
    {
        requestStackPop();
        requestStackPush(States::Menu);
    }

    return true;
}
Esempio n. 5
0
bool StateTutorial::handleInput(const sf::Event& event)
{
	if(event.type == sf::Event::MouseButtonPressed)
	{
		switch(event.mouseButton.button)
		{
		case sf::Mouse::Left:
		{
			++index_;

			if(index_ < instructionDatas.size())
				updateInstruction();

			else
				requestStackPop();

			break;
		}
		case sf::Mouse::Right:
		{
			index_ = (index_ != 0) ? index_ - 1 : index_;

			updateInstruction();

			break;
		}
		default:
			break;
		}

		return false;
	}

	return true;
}
bool TitleState::handleEvent(const sf::Event& event) {
	if (event.type == sf::Event::KeyReleased) {
		requestStackPop();
		requestStackPush(States::Game);
	}
	return true;
}
Esempio n. 7
0
void SelectionState::onExit(int code)
{
    switch (code)
    {
    case 3:
        emit requestStackPop();
        break;
    case 1:
    {
        QFile file("qml/HCIProject/GameScreen/current.txt");

        if (file.open(QIODevice::WriteOnly))
        {
            QTextStream out(&file);

            out << m_charSlots[m_selected]->property("charName").toString() << " ";
            out << m_charSlots[m_selected]->property("charInfo").toString();

            file.close();
        }
        emit requestStackPush(State::LOADING, false);
        break;
    }
    }
}
Esempio n. 8
0
bool LoadingState::update(sf::Time) {
    //si la tarea está creada, la continúo
    if (taskCreated) {
        if (loadingTask->isFinished()) {
            //si la tarea se ha terminado, comienzo el siguiente estado
            taskCreated=false;
            requestStackPop();
            requestStackPush(StatesID::Game);
            
        //avanzo en la completitud de la tarea
        } else {
            setCompletion(loadingTask->getCompletion());
        }
        
    //creo la tarea
    } else {
        context->actualLevel = new Level(*context->systemManager);
        std::string* level=new std::string("level1.xml");
        loadingTask = new LoadingLevel(context->nameLevel, context);
        loadingTask->execute();
        taskCreated = true;
    }
    
    return true;
}
Esempio n. 9
0
MenuState::MenuState(StateStack& stateStack, Context context, States::ID id)
	:
	State(stateStack, context, id),
	m_play_button(context.textures->getTexture(Textures::Button), context.fonts->getFont(Fonts::Main)),
	m_exit_button(context.textures->getTexture(Textures::Button), context.fonts->getFont(Fonts::Main)),
	m_background(*context.textures->getTexture(Textures::Titlescreen)),
	m_background_move(true),
	m_button_fade(false)
{
	// Play button
	m_play_button.setAction([this] ()
	{
		requestStackPop();
		requestStackPush(States::Game);
	});
	m_play_button.setText("Play");
	m_play_button.setPosition(1280/2, 720/2 + 40);

	// Exit button
	m_exit_button.setAction([this] ()
	{
		requestStackClear();
	});
	m_exit_button.setText("Exit");
	m_exit_button.setPosition(1280/2, 720/2 + 80);

	// Background thing
	m_background.setPosition(640 - m_background.getLocalBounds().width/2, 360 - m_background.getLocalBounds().height/2);

	context.mouse->setState(gui::Mouse::Neutral);
}
Esempio n. 10
0
bool GameState::handleEvent(const sf::Event& event)
{
	// Game input handling
	CommandQueue& commands = mWorld.getCommandQueue();
	mPlayer.handleEvent(event, commands);

	// Escape pressed, trigger the pause screen
	if (event.type == sf::Event::KeyPressed && 
		event.key.code == sf::Keyboard::Escape)
	{
		requestStackPush(States::Pause);
	}

	// F3 is pressed, so bring up the debug overlay
	else if (event.type == sf::Event::KeyPressed && 
		event.key.code == sf::Keyboard::F3)
	{
		if (mDebugOverlay == false)
		{
			requestStackPush(States::Debug);
			mDebugOverlay = true;
		}
		else
		{
			requestStackPop();
			mDebugOverlay = false;
		}
	}

		

	return true;
}
Esempio n. 11
0
void ColorPickerState::renderBottomScreen(cpp3ds::Window &window)
{
	window.draw(m_background);
	window.draw(m_vertices);

	if (m_position != cpp3ds::Vector2f(0, 0))
	{
		GLubyte *pixels = (GLubyte*) malloc(3);
		if (pixels) {
			glReadPixels(static_cast<GLint>(m_position.x), static_cast<GLint>(m_position.y), 1, 1, GL_BGR, GL_UNSIGNED_BYTE, pixels);
			cpp3ds::Color color = cpp3ds::Color(pixels[2], pixels[1], pixels[0]);
			free(pixels);

			// Bad solution to ignore black picked up from crosshair image
			if (color != cpp3ds::Color::Black)
				m_selectedColor = color;

			// Set context color and exit this state when color is picked
			if (m_picked) {
				getContext().color = m_selectedColor;
				getContext().client.sendColor(m_selectedColor);
				requestStackPop();
			}

			m_background.setFillColor(m_selectedColor);
		}

		window.draw(m_selector);
	}
}
PauseState::PauseState(StateStack& stack, Context context)
: State(stack, context)
, mBackgroundSprite()
, mPausedText()
, mGUIContainer()
{
	sf::Font& font = context.fonts->get(Fonts::Main);
	sf::Vector2f windowSize(context.window->getSize());

	mPausedText.setFont(font);
	mPausedText.setString("Game Paused");	
	mPausedText.setCharacterSize(70);
	centerOrigin(mPausedText);
	mPausedText.setPosition(0.5f * windowSize.x, 0.4f * windowSize.y);

	auto returnButton = std::make_shared<GUI::Button>(*context.fonts, *context.textures);
	returnButton->setPosition(0.5f * windowSize.x - 100, 0.4f * windowSize.y + 75);
	returnButton->setText("Return");
	returnButton->setCallback([this] ()
	{
		requestStackPop();
	});

	auto backToMenuButton = std::make_shared<GUI::Button>(*context.fonts, *context.textures);
	backToMenuButton->setPosition(0.5f * windowSize.x - 100, 0.4f * windowSize.y + 125);
	backToMenuButton->setText("Back to menu");
	backToMenuButton->setCallback([this] ()
	{
		requestStateClear();
		requestStackPush(States::Menu);
	});

	mGUIContainer.pack(returnButton);
	mGUIContainer.pack(backToMenuButton);
}
Esempio n. 13
0
    bool WinnerState::handleEvent(const sf::Event& event)
    {
        if (event.type == sf::Event::KeyPressed) {
            requestStackPop();
        }

        return false;
    }
Esempio n. 14
0
void MenuPauseState::close()
{
    requestStackPop();

    auto msg = m_messageBus.post<xy::Message::UIEvent>(xy::Message::UIMessage);
    msg->type = xy::Message::UIEvent::MenuClosed;
    msg->value = 0.f;
    msg->stateID = States::ID::Pause;
}
Esempio n. 15
0
bool TitleState::handleEvent(const sf::Event& event) {
    // If any key is pressed, trigger the next screen
    if (event.type == sf::Event::KeyReleased) {
        requestStackPop();
        requestStackPush(States::Menu);
    }

    return true;
}
Esempio n. 16
0
bool PauseState::handleEvent(const sf::Event &event)
{
	if (event.type == sf::Event::KeyPressed &&
		event.key.code == sf::Keyboard::P)
	{
		requestStackPop();
	}
	return false;
}
Esempio n. 17
0
bool MenuState::handleEvent(const sf::Event& event)
{
	// The demonstration menu logic
	if (event.type != sf::Event::KeyPressed)
		return false;

	if (event.key.code == sf::Keyboard::Return)
	{
		if (mOptionIndex == Play)
		{
			requestStackPop();
			requestStackPush(States::Game);
		}
		else if (mOptionIndex == Exit)
		{
			// The exit option was chosen, by removing itself, the stack will be empty, and the game will know it is time to close.
			requestStackPop();
		}
	}

	else if (event.key.code == sf::Keyboard::Up)
	{
		// Decrement and wrap-around
		if (mOptionIndex > 0)
			mOptionIndex--;
		else
			mOptionIndex = mOptions.size() - 1;

		updateOptionText();
	}

	else if (event.key.code == sf::Keyboard::Down)
	{
		// Increment and wrap-around
		if (mOptionIndex < mOptions.size() - 1)
			mOptionIndex++;
		else
			mOptionIndex = 0;

		updateOptionText();
	}

	return true;
}
Esempio n. 18
0
//private
void MenuHighScoreState::buildMenu(const sf::Font& font)
{
    const float centreX = xy::DefaultSceneSize.x / 2.f;

    const auto& scores = getContext().appInstance.getScores();
    auto list = xy::UI::create<xy::UI::ScoreList>(font);
    list->setAlignment(xy::UI::Alignment::Centre);
    list->setPosition(centreX, 590.f);
    list->setList(scores);
    list->setIndex(getContext().appInstance.getLastScoreIndex());
    m_uiContainer.addControl(list);

    auto upScroll = xy::UI::create<xy::UI::Button>(font, m_textureResource.get("assets/images/ui/scroll_arrow_vertical.png"));
    upScroll->setAlignment(xy::UI::Alignment::Centre);
    upScroll->setPosition(1310, 470.f);
    upScroll->addCallback([list]()
    {
        list->scroll(list->getVerticalSpacing());
    });
    m_uiContainer.addControl(upScroll);

    auto downScroll = xy::UI::create<xy::UI::Button>(font, m_textureResource.get("assets/images/ui/scroll_arrow_vertical.png"));
    downScroll->setAlignment(xy::UI::Alignment::Centre);
    downScroll->setRotation(180.f);
    downScroll->setPosition(1310.f, 720.f);
    downScroll->addCallback([list]()
    {
        list->scroll(-list->getVerticalSpacing());
    });
    m_uiContainer.addControl(downScroll);
    
    auto button = xy::UI::create<xy::UI::Button>(font, m_textureResource.get("assets/images/ui/start_button.png"));
    button->setString("OK");
    button->setAlignment(xy::UI::Alignment::Centre);
    button->setPosition(centreX, 875.f);
    button->addCallback([this]()
    {
        auto msg = m_messageBus.post<xy::Message::UIEvent>(xy::Message::UIMessage);
        msg->type = xy::Message::UIEvent::MenuClosed;
        msg->value = 0.f;
        msg->stateID = (m_endGame) ? States::ID::HighScoresEnd : States::ID::HighScoresMenu;

        if (m_endGame)
        {
            requestStackClear();
            requestStackPush(States::ID::MenuBackground);
        }
        else
        {
            requestStackPop();
            requestStackPush(States::ID::MenuMain);
        }
        
    });
    m_uiContainer.addControl(button);
}
Esempio n. 19
0
bool
LoadingState::update( sf::Time dt ) {
    if ( mLoadingTask.isFinished() ) {
        requestStackPop();
        requestStackPush( States::Game );
    } else {
        setCompletion( mLoadingTask.getCompletion() );
    }
    return true;
}
Esempio n. 20
0
bool TitleState::handleEvent(const sf::Event& event)
{
    if (event.type == sf::Event::KeyPressed)
    {
        requestStackPop();
        requestStackPush(States::ID::Menu);
    }

    return true;
}
Esempio n. 21
0
bool LevelSelectState::handleEvent(const sf::Event &event){
    
    if (event.type == sf::Event::KeyPressed){
        mLevelContainer->handleEvent(event);
        if (event.key.code == sf::Keyboard::Escape){
            requestStackPop();
            requestStackPush(ID::Menu);
        }
    }
    return false;
}
Esempio n. 22
0
bool IntroState::handleEvent(const sf::Event& event)
{
	// If any key is pressed, trigger the next screen
	if (event.type == sf::Event::KeyReleased)
	{
		requestStackPop();
		// requestStackPush(States::Menu); // TODO ITE enable
	}

	return false; // dont forward events
}
Esempio n. 23
0
bool EndState::handleEvent(const sf::Event& e)
{
	if (e.type == sf::Event::KeyPressed && e.key.code == sf::Keyboard::Escape)
	{
		ScoreGenerator& scores = *getContext().score;
		saveScore(scores.getScoreString());
		scores.resetScores();
		requestStackPop();
		requestStackPush(States::Title);
	}
	return false;
}
Esempio n. 24
0
void ScoreState::closeMenu()
{
    requestStackPop();
    requestStackPush(States::ID::Menu);

    Message msg;
    msg.type = Message::Type::UI;
    msg.ui.type = Message::UIEvent::MenuClosed;
    msg.ui.value = 0.f;
    msg.ui.stateId = States::ID::Score;
    m_messageBus.send(msg);
}
Esempio n. 25
0
bool TitleState::handleEvent(const sf::Event event)
{
	// Any key press will push the menu state
	if(event.type == sf::Event::KeyPressed)
	{
		requestStackPop();
		requestStackPush(States::MENU);
	}

	// True means, this state doesn't block states under it
	return true;
}
Esempio n. 26
0
bool OptionState::handleEvent(const sf::Event &event) {

    if (event.type == sf::Event::KeyPressed) {
        if (event.key.code == sf::Keyboard::Escape)
            requestStackPop();
        else if ((event.key.code == sf::Keyboard::Return) ||
                 (event.key.code == sf::Keyboard::Space))
            applyOptions();
    }
    mGUIContainer.handleEvent(event);
    return false;
}
Esempio n. 27
0
MenuState::MenuState(StateStack& stack, Context context):
    State(stack, context),
    m_gui(*context.window),
    // m_options(),
    // m_optionIndex(0),
    m_sounds(*context.sounds)
{
        sf::Texture& texture = context.textures->get(Textures::TitleScreen);
        sf::Font& font = context.fonts->get(Fonts::Main);

        m_backgroundSprite.setTexture(texture);

        // setup GUI
        m_gui.setFont(font);

        tgui::Button::Ptr playButton = tgui::Button::create();
        playButton->setSize(200, 50);
        playButton->setPosition(context.window->getView().getSize() / 2.f);
        playButton->setText("Start");
        playButton->connect("pressed", [&](){ requestStackPop(); requestStackPush(States::Game); });
        m_gui.add(playButton);

        tgui::Button::Ptr optionsButton = tgui::Button::create();
        optionsButton->setSize(200, 50);
        optionsButton->setPosition(context.window->getView().getSize() / 2.f + sf::Vector2f(0.f, 75.f));
        optionsButton->setText("Options");
        m_gui.add(optionsButton);

        tgui::Button::Ptr exitButton = tgui::Button::create();
        exitButton->setSize(200, 50);
        exitButton->setPosition(context.window->getView().getSize() / 2.f + sf::Vector2f(0.f, 150.f));
        exitButton->setText("Exit");
        exitButton->connect("pressed", [&](){ requestStackPop(); });
        m_gui.add(exitButton);

	/* TODO Title music
        context.music->setVolume(25.f);
        context.music->play(Music::MenuTheme);*/
}
Esempio n. 28
0
bool LoadingState::update(sf::Time)
{
	// Update the progress bar from the remote task or finish it
	if (m_loadingTask.isFinished())
	{
		requestStackPop();
		requestStackPush(States::ID::Game);
	}
	else
	{
		setCompletion(m_loadingTask.getCompletion());
	}
	return true;
}
Esempio n. 29
0
bool GameState::update(sf::Time dt)
{
	GlobalConfig& g = GlobalConfig::get();

	mWorld.update(dt);
	mClick.update(dt);
	CommandQueue& commands = mWorld.getCommandQueue();
	if (mWorld.getScoreObject()->getTotalCustomers() >= g.TOTAL_CUSTOMERS)
	{
		requestStackPop();
		requestStackPush(States::End);
	}
	return true;
}
Esempio n. 30
0
bool MenuState::handleEvent(const sf::Event& event)
{
	if (event.type != sf::Event::KeyPressed)
		return false;

	if (event.key.code == sf::Keyboard::Up)
	{
		if (index > 0)
			index--;
		else
			index = options.size() - 1;

		updateOptionText();
	}
	else if (event.key.code == sf::Keyboard::Down)
	{
		if (index < options.size() - 1)
			index++;
		else
			index = 0;

		updateOptionText();
	}
	else if (event.key.code == sf::Keyboard::Return)
	{
		if (index == Play)
		{
			requestStackPop();
			requestStackPush(States::game);
		}
		else if (index == Exit)
		{
			requestStackPop();
		}
	}
	return true;
}