CTutorialWindow.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * CTutorialWindow.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CTutorialWindow.h"
  12. #include "../eventsSDL/InputHandler.h"
  13. #include "../../lib/CConfigHandler.h"
  14. #include "../ConditionalWait.h"
  15. #include "../../lib/texts/CGeneralTextHandler.h"
  16. #include "../../lib/VCMI_Lib.h"
  17. #include "../CPlayerInterface.h"
  18. #include "../GameEngine.h"
  19. #include "../GameInstance.h"
  20. #include "../gui/Shortcut.h"
  21. #include "../gui/WindowHandler.h"
  22. #include "../widgets/Images.h"
  23. #include "../widgets/Buttons.h"
  24. #include "../widgets/TextControls.h"
  25. #include "../widgets/VideoWidget.h"
  26. #include "../render/Canvas.h"
  27. CTutorialWindow::CTutorialWindow(const TutorialMode & m)
  28. : CWindowObject(BORDERED, ImagePath::builtin("DIBOXBCK")), mode { m }, page { 0 }
  29. {
  30. OBJECT_CONSTRUCTION;
  31. pos = Rect(pos.x, pos.y, 380, 400); //video: 320x240
  32. background = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, pos.w, pos.h));
  33. updateShadow();
  34. center();
  35. addUsedEvents(LCLICK);
  36. if(mode == TutorialMode::TOUCH_ADVENTUREMAP) videos = { "RightClick", "MapPanning", "MapZooming", "RadialWheel" };
  37. else if(mode == TutorialMode::TOUCH_BATTLE) videos = { "BattleDirection", "BattleDirectionAbort", "AbortSpell" };
  38. labelTitle = std::make_shared<CLabel>(190, 15, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, VLC->generaltexth->translate("vcmi.tutorialWindow.title"));
  39. labelInformation = std::make_shared<CMultiLineLabel>(Rect(5, 40, 370, 60), EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, "");
  40. buttonOk = std::make_shared<CButton>(Point(159, 367), AnimationPath::builtin("IOKAY"), CButton::tooltip(), std::bind(&CTutorialWindow::exit, this), EShortcut::GLOBAL_RETURN); //62x28
  41. buttonLeft = std::make_shared<CButton>(Point(5, 217), AnimationPath::builtin("HSBTNS3"), CButton::tooltip(), std::bind(&CTutorialWindow::previous, this), EShortcut::MOVE_LEFT); //22x46
  42. buttonRight = std::make_shared<CButton>(Point(352, 217), AnimationPath::builtin("HSBTNS5"), CButton::tooltip(), std::bind(&CTutorialWindow::next, this), EShortcut::MOVE_RIGHT); //22x46
  43. setContent();
  44. }
  45. void CTutorialWindow::setContent()
  46. {
  47. OBJECT_CONSTRUCTION;
  48. auto video = VideoPath::builtin("tutorial/" + videos[page]);
  49. videoPlayer = std::make_shared<VideoWidget>(Point(30, 120), video, false);
  50. buttonLeft->block(page<1);
  51. buttonRight->block(page>videos.size() - 2);
  52. labelInformation->setText(VLC->generaltexth->translate("vcmi.tutorialWindow.decription." + videos[page]));
  53. }
  54. void CTutorialWindow::openWindowFirstTime(const TutorialMode & m)
  55. {
  56. if(ENGINE->input().getCurrentInputMode() == InputMode::TOUCH && !persistentStorage["gui"]["tutorialCompleted" + std::to_string(m)].Bool())
  57. {
  58. if(GAME->interface())
  59. GAME->interface()->showingDialog->setBusy();
  60. ENGINE->windows().pushWindow(std::make_shared<CTutorialWindow>(m));
  61. Settings s = persistentStorage.write["gui"]["tutorialCompleted" + std::to_string(m)];
  62. s->Bool() = true;
  63. }
  64. }
  65. void CTutorialWindow::exit()
  66. {
  67. if(GAME->interface())
  68. GAME->interface()->showingDialog->setFree();
  69. close();
  70. }
  71. void CTutorialWindow::next()
  72. {
  73. page++;
  74. setContent();
  75. deactivate();
  76. activate();
  77. }
  78. void CTutorialWindow::previous()
  79. {
  80. page--;
  81. setContent();
  82. deactivate();
  83. activate();
  84. }