guiscenemanager.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "gui/guiscenemanager.h"
  2. #include "gui/gui.h"
  3. #include "gui/mainmenu.h"
  4. #include "hotseatgame/gui/recruitmentscene.h"
  5. #include "hotseatgame/gui/playervsplayerintro.h"
  6. #include "hotseatgame/gui/prebattlescene.h"
  7. #include "hotseatgame/gui/hotseatgame.h"
  8. #include <QResource>
  9. #include <QApplication>
  10. #include <QFontDatabase>
  11. GuiSceneManager::GuiSceneManager(QObject *parent) : QObject(parent) {
  12. gui_ = new GUI();
  13. gui_->show();
  14. current_scene_ = "none";
  15. QResource::registerResource(QApplication::applicationDirPath() + "/res/game_ui_data.gtr");
  16. QResource::registerResource(QApplication::applicationDirPath() + "/res/unit_data.gtr");
  17. QResource::registerResource(QApplication::applicationDirPath() + "/res/spell_data.gtr");
  18. QResource::registerResource(QApplication::applicationDirPath() + "/res/effect_data.gtr");
  19. QFontDatabase::addApplicationFont(":/assets/fonts/barocco-initial.ttf");
  20. QFontDatabase::addApplicationFont(":/assets/fonts/viking-cyr.ttf");
  21. registerScene("main_menu", new MainMenu(gui_->mainContentScene()));
  22. registerScene("pvp_intro", new PlayerVsPlayerIntro(gui_->mainContentScene()));
  23. registerScene("recruit_army", new RecruitmentScene(gui_->mainContentScene()));
  24. registerScene("prebattle", new PreBattleScene(gui_->mainContentScene()));
  25. registerScene("hotseatgame", new HotSeatGame());
  26. changeScene("main_menu");
  27. }
  28. GuiSceneManager::~GuiSceneManager() {}
  29. bool GuiSceneManager::registerScene(QString scene_name, Scene* scene) {
  30. if (scene_name == "none")
  31. return false;
  32. if (scenes_.count(scene_name) != 0) {
  33. delete scene;
  34. return false;
  35. }
  36. scenes_[scene_name] = scene;
  37. return true;
  38. }
  39. bool GuiSceneManager::changeScene(QString scene_name, QString args) {
  40. if (scene_name == "main_window") {
  41. return false;
  42. }
  43. if (current_scene_ != "none")
  44. scenes_[current_scene_]->hide();
  45. scenes_[scene_name]->parseArgs(args);
  46. scenes_[scene_name]->init();
  47. scenes_[scene_name]->show();
  48. current_scene_ = scene_name;
  49. return true;
  50. }
  51. bool GuiSceneManager::hideMainWindow() {
  52. gui_->hide();
  53. return true;
  54. }
  55. bool GuiSceneManager::showMainWindow() {
  56. gui_->show();
  57. return true;
  58. }
  59. bool GuiSceneManager::hideDetachedScene(QString scene_name) {
  60. if (scenes_.count(scene_name) == 0 || !scenes_[scene_name])
  61. return false;
  62. scenes_[scene_name]->hide();
  63. return true;
  64. }
  65. bool GuiSceneManager::showDetachedScene(QString scene_name, QString args) {
  66. if (scenes_.count(scene_name) == 0 || !scenes_[scene_name])
  67. return false;
  68. scenes_[scene_name]->parseArgs(args);
  69. scenes_[scene_name]->init();
  70. scenes_[scene_name]->show();
  71. return true;
  72. }