示例#1
0
PauseMenuPanel::PauseMenuPanel(GameState *gameState)
	: Panel(gameState)
{
	this->playerNameTextBox = [gameState]()
	{
		int x = 17;
		int y = 154;
		Color color(215, 121, 8);
		std::string text = gameState->getGameData()->getPlayer().getFirstName();
		auto &font = gameState->getFontManager().getFont(FontName::Char);
		auto alignment = TextAlignment::Left;
		return std::unique_ptr<TextBox>(new TextBox(
			x,
			y,
			color,
			text,
			font,
			alignment,
			gameState->getRenderer()));
	}();

	this->musicTextBox = [gameState]()
	{
		Int2 center(127, 96);
		Color color(12, 73, 16);
		std::string text = std::to_string(static_cast<int>(
			std::round(gameState->getOptions().getMusicVolume() * 100.0)));
		auto &font = gameState->getFontManager().getFont(FontName::Arena);
		auto alignment = TextAlignment::Center;
		return std::unique_ptr<TextBox>(new TextBox(
			center,
			color,
			text,
			font,
			alignment,
			gameState->getRenderer()));
	}();

	this->soundTextBox = [gameState]()
	{
		Int2 center(54, 96);
		Color color(12, 73, 16);
		std::string text = std::to_string(static_cast<int>(
			std::round(gameState->getOptions().getSoundVolume() * 100.0)));
		auto &font = gameState->getFontManager().getFont(FontName::Arena);
		auto alignment = TextAlignment::Center;
		return std::unique_ptr<TextBox>(new TextBox(
			center,
			color,
			text,
			font,
			alignment,
			gameState->getRenderer()));
	}();

	this->loadButton = []()
	{
		int x = 65;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			std::unique_ptr<Panel> loadPanel(new LoadGamePanel(gameState));
			gameState->setPanel(std::move(loadPanel));
		};
		return std::unique_ptr<Button>(new Button(x, y, 64, 29, function));
	}();

	this->exitButton = []()
	{
		int x = 193;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			SDL_Event evt;
			evt.quit.type = SDL_QUIT;
			evt.quit.timestamp = 0;
			SDL_PushEvent(&evt);
		};
		return std::unique_ptr<Button>(new Button(x, y, 64, 29, function));
	}();

	this->newButton = []()
	{
		int x = 0;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			gameState->setGameData(nullptr);

			std::unique_ptr<Panel> mainMenuPanel(new MainMenuPanel(gameState));
			gameState->setPanel(std::move(mainMenuPanel));
			gameState->setMusic(MusicName::PercIntro);
		};
		return std::unique_ptr<Button>(new Button(x, y, 65, 29, function));
	}();

	this->saveButton = []()
	{
		int x = 129;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			// SaveGamePanel...
			//std::unique_ptr<Panel> optionsPanel(new OptionsPanel(gameState));
			//gameState->setPanel(std::move(optionsPanel));
		};
		return std::unique_ptr<Button>(new Button(x, y, 64, 29, function));
	}();

	this->resumeButton = []()
	{
		int x = 257;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			std::unique_ptr<Panel> gamePanel(new GameWorldPanel(gameState));
			gameState->setPanel(std::move(gamePanel));
		};
		return std::unique_ptr<Button>(new Button(x, y, 64, 29, function));
	}();

	this->musicUpButton = [this]()
	{
		int x = 119;
		int y = 79;
		auto function = [this](GameState *gameState)
		{
			Options &options = gameState->getOptions();
			options.setMusicVolume(std::min(options.getMusicVolume() + 0.050, 1.0));

			AudioManager &audioManager = gameState->getAudioManager();
			audioManager.setMusicVolume(options.getMusicVolume());

			// Update the music volume text.
			this->updateMusicText(options.getMusicVolume());
		};
		return std::unique_ptr<Button>(new Button(x, y, 17, 9, function));
	}();

	this->musicDownButton = [this]()
	{
		int x = 119;
		int y = 104;
		auto function = [this](GameState *gameState)
		{
			Options &options = gameState->getOptions();
			options.setMusicVolume(std::max(options.getMusicVolume() - 0.050, 0.0));

			AudioManager &audioManager = gameState->getAudioManager();
			audioManager.setMusicVolume(options.getMusicVolume());

			// Update the music volume text.
			this->updateMusicText(options.getMusicVolume());
		};
		return std::unique_ptr<Button>(new Button(x, y, 17, 9, function));
	}();

	this->soundUpButton = [this]()
	{
		int x = 46;
		int y = 79;
		auto function = [this](GameState *gameState)
		{
			Options &options = gameState->getOptions();
			options.setSoundVolume(std::min(options.getSoundVolume() + 0.050, 1.0));

			AudioManager &audioManager = gameState->getAudioManager();
			audioManager.setSoundVolume(options.getSoundVolume());

			// Update the sound volume text.
			this->updateSoundText(options.getSoundVolume());
		};
		return std::unique_ptr<Button>(new Button(x, y, 17, 9, function));
	}();

	this->soundDownButton = [this]()
	{
		int x = 46;
		int y = 104;
		auto function = [this](GameState *gameState)
		{
			Options &options = gameState->getOptions();
			options.setSoundVolume(std::max(options.getSoundVolume() - 0.050, 0.0));

			AudioManager &audioManager = gameState->getAudioManager();
			audioManager.setSoundVolume(options.getSoundVolume());

			// Update the sound volume text.
			this->updateSoundText(options.getSoundVolume());
		};
		return std::unique_ptr<Button>(new Button(x, y, 17, 9, function));
	}();

	// Store these because of the order game data is deleted when going
	// to the main menu.
	auto &player = gameState->getGameData()->getPlayer();
	this->headsFilename = PortraitFile::getHeads(
		player.getGenderName(), player.getRaceName(), true);
	this->portraitID = player.getPortraitID();
	this->classCanCastMagic = player.getCharacterClass().canCastMagic();
}
示例#2
0
PauseMenuPanel::PauseMenuPanel(GameState *gameState)
	: Panel(gameState)
{
	this->playerNameTextBox = [gameState]()
	{
		int x = 17;
		int y = 154;
		Color color(215, 121, 8);
		std::string text = gameState->getGameData()->getPlayer().getFirstName();
		auto fontName = FontName::Char;
		return std::unique_ptr<TextBox>(new TextBox(
			x,
			y,
			color,
			text,
			fontName,
			gameState->getTextureManager(),
			gameState->getRenderer()));
	}();

	this->loadButton = []()
	{
		int x = 65;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			std::unique_ptr<Panel> loadPanel(new LoadGamePanel(gameState));
			gameState->setPanel(std::move(loadPanel));
		};
		return std::unique_ptr<Button>(new Button(x, y, 64, 29, function));
	}();

	this->exitButton = []()
	{
		int x = 193;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			SDL_Event evt;
			evt.quit.type = SDL_QUIT;
			evt.quit.timestamp = 0;
			SDL_PushEvent(&evt);
		};
		return std::unique_ptr<Button>(new Button(x, y, 64, 29, function));
	}();

	this->newButton = []()
	{
		int x = 0;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			gameState->setGameData(nullptr);

			std::unique_ptr<Panel> mainMenuPanel(new MainMenuPanel(gameState));
			gameState->setPanel(std::move(mainMenuPanel));
			gameState->setMusic(MusicName::PercIntro);
		};
		return std::unique_ptr<Button>(new Button(x, y, 65, 29, function));
	}();

	this->saveButton = []()
	{
		int x = 129;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			// SaveGamePanel...
			//std::unique_ptr<Panel> optionsPanel(new OptionsPanel(gameState));
			//gameState->setPanel(std::move(optionsPanel));
		};
		return std::unique_ptr<Button>(new Button(x, y, 64, 29, function));
	}();

	this->resumeButton = []()
	{
		int x = 257;
		int y = 118;
		auto function = [](GameState *gameState)
		{
			std::unique_ptr<Panel> gamePanel(new GameWorldPanel(gameState));
			gameState->setPanel(std::move(gamePanel));
		};
		return std::unique_ptr<Button>(new Button(x, y, 64, 29, function));
	}();
}