void MenuButton::mousePressEvent ( QGraphicsSceneMouseEvent * event ) { QGraphicsItem::mousePressEvent(event); if(event->button() != Qt::LeftButton) return; if(currentMenu) { currentMenu->setFocus(); //BUG: doesnt seem to work return; } QDialog *menu = new QDialog(panelWindow); menu->move(event->screenPos().x(), event->screenPos().y()); QVBoxLayout *layout = new QVBoxLayout(); QCheckBox *editModeCheck = new QCheckBox("Edit Panel", menu); editModeCheck->setChecked(editMode); connect(editModeCheck, SIGNAL(clicked(bool)), panelWindow, SLOT(setEditMode(bool))); connect(editModeCheck, SIGNAL(clicked(bool)), this, SLOT(setEditMode(bool))); layout->addWidget(editModeCheck); QPushButton *addButton = new QPushButton("Add Item", menu); connect(addButton, SIGNAL(clicked()), panelWindow, SLOT(addItem())); layout->addWidget(addButton); QPushButton *saveButton = new QPushButton("Save panel", menu); connect(saveButton, SIGNAL(clicked()), panelWindow, SLOT(savePanel())); layout->addWidget(saveButton); QPushButton *loadButton = new QPushButton("Load panel", menu); connect(loadButton, SIGNAL(clicked()), panelWindow, SLOT(loadPanel())); layout->addWidget(loadButton); QPushButton *settingsButton = new QPushButton("App Settings", menu); connect(settingsButton, SIGNAL(clicked()), panelWindow, SLOT(showSettings())); connect(settingsButton, SIGNAL(clicked()), this, SLOT(closeCurrentMenu())); layout->addWidget(settingsButton); QPushButton *closeButton = new QPushButton("Close", menu); connect(closeButton, SIGNAL(clicked()), this, SLOT(closeCurrentMenu())); layout->addWidget(closeButton); QPushButton *quitButton = new QPushButton("Quit", menu); connect(quitButton, SIGNAL(clicked()), panelWindow, SLOT(quit())); layout->addWidget(quitButton); currentMenu = menu; connect(currentMenu, SIGNAL(finished(int)), this, SLOT(closeCurrentMenu())); menu->setLayout(layout); menu->setModal(false); menu->show(); }
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(); }
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)); }(); }