mainmenu.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "gui/mainmenu.h"
  2. #include "gui/guiscenemanager.h"
  3. #include "soundengine.h"
  4. #include "ui_mainmenu.h"
  5. #include <QString>
  6. #include <QApplication>
  7. #include <QMovie>
  8. #include <QFileInfo>
  9. MainMenu::MainMenu(QWidget *parent) :
  10. Scene(parent),
  11. ui(new Ui::MainMenu)
  12. {
  13. ui->setupUi(this);
  14. // Load animated GIF
  15. movie = new QMovie(":/assets/main_menu/tree.gif");
  16. watcher = new ButtonHoverWatcher(this);
  17. ui->hotseat_button->installEventFilter(watcher);
  18. ui->about_us_button->installEventFilter(watcher);
  19. ui->leave_game_button->installEventFilter(watcher);
  20. ui->tree_label->setMovie(movie);
  21. movie->start();
  22. }
  23. MainMenu::~MainMenu()
  24. {
  25. delete movie;
  26. delete ui;
  27. delete watcher;
  28. }
  29. void MainMenu::init()
  30. {
  31. SoundEngine::getInstance().playlist().addMedia(QUrl("qrc:/assets/main_menu/main_menu_music_1.mp3"));
  32. SoundEngine::getInstance().player().play();
  33. }
  34. ButtonHoverWatcher::ButtonHoverWatcher(QObject * parent) :
  35. QObject(parent)
  36. {}
  37. bool ButtonHoverWatcher::eventFilter(QObject * watched, QEvent * event) {
  38. QPushButton * button = qobject_cast<QPushButton*>(watched);
  39. if (!button) {
  40. return false;
  41. }
  42. if (event->type() == QEvent::Enter) {
  43. button->setStyleSheet("font: 10pt \"Viking Cyr\";"
  44. "color: rgb(255, 255, 0);"
  45. "border-image: url(:/assets/main_menu/" + button->objectName() + "_hover.png);");
  46. SoundEngine::getInstance().playAsync("qrc:/assets/main_menu/button_hover.mp3");
  47. return false;
  48. }
  49. if (event->type() == QEvent::Leave){
  50. button->setStyleSheet("font: 10pt \"Viking Cyr\";"
  51. "color: rgb(255, 255, 0);"
  52. "border-image: url(:/assets/main_menu/" + button->objectName() + ".png);");
  53. return false;
  54. }
  55. if (event->type() == QEvent::MouseButtonPress) {
  56. qDebug() << "CLICK!!";
  57. SoundEngine::getInstance().playAsync("qrc:/assets/main_menu/button_click.mp3");
  58. return false;
  59. }
  60. return false;
  61. }
  62. void MainMenu::on_hotseat_button_clicked() {
  63. GuiSceneManager::getInstance().changeScene("pvp_intro");
  64. }
  65. void MainMenu::on_leave_game_button_clicked() {
  66. QApplication::exit();
  67. }