mainmenu.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "main_menu/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. SoundEngine::getInstance().playAsync("qrc:/assets/main_menu/button_click.mp3");
  57. return false;
  58. }
  59. return false;
  60. }
  61. void MainMenu::on_hotseat_button_clicked() {
  62. GuiSceneManager::getInstance().changeScene("pvp_intro");
  63. }
  64. void MainMenu::on_leave_game_button_clicked() {
  65. QApplication::exit();
  66. }