guiscenemanager.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "gui/guiscenemanager.h"
  2. #include "gui/mainmenu.h"
  3. #include "hotseatgame/gui/recruitmentscene.h"
  4. #include "hotseatgame/gui/playervsplayerintro.h"
  5. #include "hotseatgame/gui/prebattlescene.h"
  6. #include "hotseatgame/gui/hotseatgame.h"
  7. #include <QResource>
  8. #include <QApplication>
  9. #include <QFontDatabase>
  10. GuiSceneManager::GuiSceneManager(QObject *parent) : QObject(parent) {
  11. window_ = new QMainWindow(nullptr, Qt::Window | Qt::FramelessWindowHint);
  12. window_->setWindowTitle("Супер-мега-клёвая-игрушка-название-которой-мы-ещё-не-придумали");
  13. window_->setWindowState(Qt::WindowFullScreen);
  14. window_->show();
  15. current_scene_ = "none";
  16. QResource::registerResource(QApplication::applicationDirPath() + "/res/game_ui_data.gtr");
  17. QResource::registerResource(QApplication::applicationDirPath() + "/res/unit_data.gtr");
  18. QResource::registerResource(QApplication::applicationDirPath() + "/res/spell_data.gtr");
  19. QResource::registerResource(QApplication::applicationDirPath() + "/res/effect_data.gtr");
  20. QFontDatabase::addApplicationFont(":/assets/fonts/barocco-initial.ttf");
  21. QFontDatabase::addApplicationFont(":/assets/fonts/viking-cyr.ttf");
  22. registerScene("main_menu", new MainMenu());
  23. registerScene("pvp_intro", new PlayerVsPlayerIntro());
  24. registerScene("recruit_army", new RecruitmentScene());
  25. registerScene("prebattle", new PreBattleScene());
  26. registerScene("hotseatgame", new HotSeatGame());
  27. changeScene("main_menu");
  28. }
  29. GuiSceneManager::~GuiSceneManager() {}
  30. bool GuiSceneManager::registerScene(QString scene_name, Scene* scene) {
  31. if (scene_name == "none")
  32. return false;
  33. if (scenes_.count(scene_name) != 0) {
  34. delete scene;
  35. return false;
  36. }
  37. scenes_[scene_name] = scene;
  38. return true;
  39. }
  40. bool GuiSceneManager::changeScene(QString scene_name, QString args) {
  41. if (scene_name == "main_window") {
  42. return false;
  43. }
  44. if (current_scene_ != "none") {
  45. scenes_[current_scene_]->deinit();
  46. scenes_[current_scene_]->hide();
  47. window_->takeCentralWidget();
  48. }
  49. scenes_[scene_name]->parseArgs(args);
  50. scenes_[scene_name]->init();
  51. window_->setCentralWidget(scenes_[scene_name]);
  52. scenes_[scene_name]->show();
  53. current_scene_ = scene_name;
  54. return true;
  55. }