CTutorialWindow.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "../CPlayerInterface.h"
  17. #include "../CGameInfo.h"
  18. #include "../gui/CGuiHandler.h"
  19. #include "../gui/Shortcut.h"
  20. #include "../gui/WindowHandler.h"
  21. #include "../widgets/Images.h"
  22. #include "../widgets/Buttons.h"
  23. #include "../widgets/TextControls.h"
  24. #include "../widgets/VideoWidget.h"
  25. #include "../render/Canvas.h"
  26. CTutorialWindow::CTutorialWindow(const TutorialMode & m)
  27. : CWindowObject(BORDERED, ImagePath::builtin("DIBOXBCK")), mode { m }, page { 0 }
  28. {
  29. OBJECT_CONSTRUCTION;
  30. pos = Rect(pos.x, pos.y, 380, 400); //video: 320x240
  31. background = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, pos.w, pos.h));
  32. updateShadow();
  33. center();
  34. addUsedEvents(LCLICK);
  35. if(mode == TutorialMode::TOUCH_ADVENTUREMAP) videos = { "RightClick", "MapPanning", "MapZooming", "RadialWheel" };
  36. else if(mode == TutorialMode::TOUCH_BATTLE) videos = { "BattleDirection", "BattleDirectionAbort", "AbortSpell" };
  37. labelTitle = std::make_shared<CLabel>(190, 15, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.tutorialWindow.title"));
  38. labelInformation = std::make_shared<CMultiLineLabel>(Rect(5, 40, 370, 60), EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, "");
  39. buttonOk = std::make_shared<CButton>(Point(159, 367), AnimationPath::builtin("IOKAY"), CButton::tooltip(), std::bind(&CTutorialWindow::exit, this), EShortcut::GLOBAL_RETURN); //62x28
  40. buttonLeft = std::make_shared<CButton>(Point(5, 217), AnimationPath::builtin("HSBTNS3"), CButton::tooltip(), std::bind(&CTutorialWindow::previous, this), EShortcut::MOVE_LEFT); //22x46
  41. buttonRight = std::make_shared<CButton>(Point(352, 217), AnimationPath::builtin("HSBTNS5"), CButton::tooltip(), std::bind(&CTutorialWindow::next, this), EShortcut::MOVE_RIGHT); //22x46
  42. setContent();
  43. }
  44. void CTutorialWindow::setContent()
  45. {
  46. OBJECT_CONSTRUCTION;
  47. auto video = VideoPath::builtin("tutorial/" + videos[page]);
  48. videoPlayer = std::make_shared<VideoWidget>(Point(30, 120), video, false);
  49. buttonLeft->block(page<1);
  50. buttonRight->block(page>videos.size() - 2);
  51. labelInformation->setText(CGI->generaltexth->translate("vcmi.tutorialWindow.decription." + videos[page]));
  52. }
  53. void CTutorialWindow::openWindowFirstTime(const TutorialMode & m)
  54. {
  55. if(GH.input().getCurrentInputMode() == InputMode::TOUCH && !persistentStorage["gui"]["tutorialCompleted" + std::to_string(m)].Bool())
  56. {
  57. if(LOCPLINT)
  58. LOCPLINT->showingDialog->setBusy();
  59. GH.windows().pushWindow(std::make_shared<CTutorialWindow>(m));
  60. Settings s = persistentStorage.write["gui"]["tutorialCompleted" + std::to_string(m)];
  61. s->Bool() = true;
  62. }
  63. }
  64. void CTutorialWindow::exit()
  65. {
  66. if(LOCPLINT)
  67. LOCPLINT->showingDialog->setFree();
  68. close();
  69. }
  70. void CTutorialWindow::next()
  71. {
  72. page++;
  73. setContent();
  74. deactivate();
  75. activate();
  76. }
  77. void CTutorialWindow::previous()
  78. {
  79. page--;
  80. setContent();
  81. deactivate();
  82. activate();
  83. }