12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "gui/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) {
- qDebug() << "CLICK!!";
- 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();
- }
|