guiscenemanager.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #define PROJECT_VERSION "v.0.3.0dev"
  15. GuiSceneManager::GuiSceneManager(QObject *parent) : QObject(parent) {
  16. window_ = new QMainWindow(nullptr, Qt::Window | Qt::FramelessWindowHint);
  17. window_->setWindowTitle(QString("Honourished ") + PROJECT_VERSION);
  18. window_->setWindowState(Qt::WindowFullScreen);
  19. window_->show();
  20. current_scene_ = "none";
  21. QResource::registerResource(QApplication::applicationDirPath() + "/res/data000.gtr");
  22. QResource::registerResource(QApplication::applicationDirPath() + "/res/data001.gtr");
  23. QResource::registerResource(QApplication::applicationDirPath() + "/res/data002.gtr");
  24. QResource::registerResource(QApplication::applicationDirPath() + "/res/data003.gtr");
  25. QResource::registerResource(QApplication::applicationDirPath() + "/res/data004.gtr");
  26. QResource::registerResource(QApplication::applicationDirPath() + "/res/data005.gtr");
  27. QResource::registerResource(QApplication::applicationDirPath() + "/res/data006.gtr");
  28. QResource::registerResource(QApplication::applicationDirPath() + "/res/data007.gtr");
  29. QResource::registerResource(QApplication::applicationDirPath() + "/res/data008.gtr");
  30. QResource::registerResource(QApplication::applicationDirPath() + "/res/data009.gtr");
  31. QFontDatabase::addApplicationFont(":/assets/common/fonts/pixel.ttf");
  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. registerScene("dialog_form", new DialogForm(window_));
  40. QTimer::singleShot(100, [=] {
  41. changeScene("main_menu");
  42. });
  43. }
  44. GuiSceneManager::~GuiSceneManager() {}
  45. bool GuiSceneManager::registerScene(QString scene_name, Scene* scene) {
  46. if (scene_name == "none")
  47. return false;
  48. if (scenes_.count(scene_name) != 0) {
  49. delete scene;
  50. return false;
  51. }
  52. scenes_[scene_name] = scene;
  53. return true;
  54. }
  55. bool GuiSceneManager::changeScene(QString scene_name, QString args) {
  56. if (scene_name == "main_window") {
  57. return false;
  58. }
  59. if (current_scene_ != "none") {
  60. scenes_[current_scene_]->deinit();
  61. scenes_[current_scene_]->hide();
  62. window_->takeCentralWidget();
  63. }
  64. scenes_[scene_name]->parseArgs(args);
  65. scenes_[scene_name]->init();
  66. window_->setCentralWidget(scenes_[scene_name]);
  67. scenes_[scene_name]->show();
  68. current_scene_ = scene_name;
  69. return true;
  70. }
  71. Scene *GuiSceneManager::getScene(QString scene_name)
  72. {
  73. return scenes_[scene_name];
  74. }
  75. bool GuiSceneManager::show(QString scene_name)
  76. {
  77. if (scenes_.count(scene_name) == 0)
  78. return false;
  79. scenes_[scene_name]->resize(window_->size());
  80. scenes_[scene_name]->show();
  81. return true;
  82. }
  83. bool GuiSceneManager::hide(QString scene_name)
  84. {
  85. if (scenes_.count(scene_name) == 0)
  86. return true;
  87. scenes_[scene_name]->hide();
  88. return false;
  89. }