guiscenemanager.cpp 3.8 KB

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