guiscenemanager.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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(QString("Honourished ") + PROJECT_VERSION);
  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/common/fonts/pixel.ttf");
  31. registerScene("main_menu", new MainMenu(window_));
  32. registerScene("main_menu_background", new MainMenuBackground(window_));
  33. registerScene("pvp_intro", new PlayerVsPlayerIntro(window_));
  34. registerScene("recruit_army", new RecruitmentScene(window_));
  35. registerScene("prebattle", new PreBattleScene(window_));
  36. registerScene("hotseatgame", new HotSeatGame(window_));
  37. registerScene("about_us", new AboutUs(window_));
  38. registerScene("dialog_form", new DialogForm(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. Scene *GuiSceneManager::getScene(QString scene_name)
  71. {
  72. return scenes_[scene_name];
  73. }
  74. bool GuiSceneManager::show(QString scene_name)
  75. {
  76. if (scenes_.count(scene_name) == 0)
  77. return false;
  78. scenes_[scene_name]->resize(window_->size());
  79. scenes_[scene_name]->show();
  80. return true;
  81. }
  82. bool GuiSceneManager::hide(QString scene_name)
  83. {
  84. if (scenes_.count(scene_name) == 0)
  85. return true;
  86. scenes_[scene_name]->hide();
  87. return false;
  88. }