#include "main_menu/mainmenu.h" #include "gui/guiscenemanager.h" #include "soundengine.h" #include "ui_mainmenu.h" #include #include #include #include MainMenu::MainMenu(QWidget *parent) : Scene(parent), ui(new Ui::MainMenu) { ui->setupUi(this); // Load animated GIF movie = new QMovie(":/assets/main_menu/tree.gif"); watcher = new ButtonHoverWatcher(this); ui->hotseat_button->installEventFilter(watcher); ui->about_us_button->installEventFilter(watcher); ui->leave_game_button->installEventFilter(watcher); ui->tree_label->setMovie(movie); movie->start(); } MainMenu::~MainMenu() { delete movie; delete ui; delete watcher; } void MainMenu::init() { SoundEngine::getInstance().playlist().addMedia(QUrl("qrc:/assets/main_menu/main_menu_music_1.mp3")); SoundEngine::getInstance().player().play(); } ButtonHoverWatcher::ButtonHoverWatcher(QObject * parent) : QObject(parent) {} bool ButtonHoverWatcher::eventFilter(QObject * watched, QEvent * event) { QPushButton * button = qobject_cast(watched); if (!button) { return false; } if (event->type() == QEvent::Enter) { button->setStyleSheet("font: 10pt \"Viking Cyr\";" "color: rgb(255, 255, 0);" "border-image: url(:/assets/main_menu/" + button->objectName() + "_hover.png);"); SoundEngine::getInstance().playAsync("qrc:/assets/main_menu/button_hover.mp3"); return false; } if (event->type() == QEvent::Leave){ button->setStyleSheet("font: 10pt \"Viking Cyr\";" "color: rgb(255, 255, 0);" "border-image: url(:/assets/main_menu/" + button->objectName() + ".png);"); return false; } if (event->type() == QEvent::MouseButtonPress) { SoundEngine::getInstance().playAsync("qrc:/assets/main_menu/button_click.mp3"); return false; } return false; } void MainMenu::on_hotseat_button_clicked() { GuiSceneManager::getInstance().changeScene("pvp_intro"); } void MainMenu::on_leave_game_button_clicked() { QApplication::exit(); }