1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include "main_menu/mainmenu.h"
- #include "gui/guiscenemanager.h"
- #include "soundengine.h"
- #include "ui_mainmenu.h"
- #include <QString>
- #include <QApplication>
- #include <QMovie>
- #include <QFileInfo>
- 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<QPushButton*>(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();
- }
|