guiscenemanager.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "gui/guiscenemanager.h"
  2. #include "ui/main_menu/mainmenu.h"
  3. #include "ui/main_menu/mainmenubackground.h"
  4. #include "ui/hotseat_recruitment/recruitmentscene.h"
  5. #include "ui/hotseat_intro/playervsplayerintro.h"
  6. #include "ui/hotseat_prebattle/prebattlescene.h"
  7. #include "ui/hotseat_game/hotseatgame.h"
  8. #include "ui/about_us/aboutus.h"
  9. #include <QResource>
  10. #include <QApplication>
  11. #include <QFontDatabase>
  12. #include <QTimer>
  13. GuiSceneManager::GuiSceneManager(QObject *parent) : QObject(parent) {
  14. window_ = new QMainWindow(nullptr, Qt::Window | Qt::FramelessWindowHint);
  15. window_->setWindowTitle("Супер-мега-клёвая-игрушка-название-которой-мы-ещё-не-придумали");
  16. window_->setWindowState(Qt::WindowFullScreen);
  17. window_->show();
  18. current_scene_ = "none";
  19. QResource::registerResource(QApplication::applicationDirPath() + "/res/data000.gtr");
  20. QResource::registerResource(QApplication::applicationDirPath() + "/res/data001.gtr");
  21. QResource::registerResource(QApplication::applicationDirPath() + "/res/data002.gtr");
  22. QResource::registerResource(QApplication::applicationDirPath() + "/res/data003.gtr");
  23. QResource::registerResource(QApplication::applicationDirPath() + "/res/data004.gtr");
  24. QResource::registerResource(QApplication::applicationDirPath() + "/res/data005.gtr");
  25. QResource::registerResource(QApplication::applicationDirPath() + "/res/data006.gtr");
  26. QResource::registerResource(QApplication::applicationDirPath() + "/res/data007.gtr");
  27. QResource::registerResource(QApplication::applicationDirPath() + "/res/data008.gtr");
  28. QResource::registerResource(QApplication::applicationDirPath() + "/res/data009.gtr");
  29. QFontDatabase::addApplicationFont(":/assets/fonts/barocco-initial.ttf");
  30. QFontDatabase::addApplicationFont(":/assets/fonts/viking-cyr.ttf");
  31. QFontDatabase::addApplicationFont(":/assets/fonts/pixel.otf");
  32. registerScene("main_menu", new MainMenu(window_));
  33. registerScene("main_menu_background", new MainMenuBackground(window_));
  34. registerScene("pvp_intro", new PlayerVsPlayerIntro(window_));
  35. registerScene("recruit_army", new RecruitmentScene(window_));
  36. registerScene("prebattle", new PreBattleScene(window_));
  37. registerScene("hotseatgame", new HotSeatGame(window_));
  38. registerScene("about_us", new AboutUs(window_));
  39. QTimer::singleShot(100, [=] {
  40. changeScene("main_menu");
  41. });
  42. }
  43. GuiSceneManager::~GuiSceneManager() {}
  44. bool GuiSceneManager::registerScene(QString scene_name, Scene* scene) {
  45. if (scene_name == "none")
  46. return false;
  47. if (scenes_.count(scene_name) != 0) {
  48. delete scene;
  49. return false;
  50. }
  51. scenes_[scene_name] = scene;
  52. return true;
  53. }
  54. bool GuiSceneManager::changeScene(QString scene_name, QString args) {
  55. if (scene_name == "main_window") {
  56. return false;
  57. }
  58. if (current_scene_ != "none") {
  59. scenes_[current_scene_]->deinit();
  60. scenes_[current_scene_]->hide();
  61. window_->takeCentralWidget();
  62. }
  63. scenes_[scene_name]->parseArgs(args);
  64. scenes_[scene_name]->init();
  65. window_->setCentralWidget(scenes_[scene_name]);
  66. scenes_[scene_name]->show();
  67. current_scene_ = scene_name;
  68. return true;
  69. }
  70. bool GuiSceneManager::show(QString scene_name)
  71. {
  72. if (scenes_.count(scene_name) == 0)
  73. return false;
  74. scenes_[scene_name]->resize(window_->size());
  75. scenes_[scene_name]->show();
  76. return true;
  77. }
  78. bool GuiSceneManager::hide(QString scene_name)
  79. {
  80. if (scenes_.count(scene_name) == 0)
  81. return true;
  82. scenes_[scene_name]->hide();
  83. return false;
  84. }