GuiSceneManager.cpp 2.4 KB

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