2
0

CTutorialWindow.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/CGeneralTextHandler.h"
  16. #include "../CPlayerInterface.h"
  17. #include "../CGameInfo.h"
  18. #include "../CVideoHandler.h"
  19. #include "../gui/CGuiHandler.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 "../render/Canvas.h"
  26. CTutorialWindow::CTutorialWindow(const TutorialMode & m)
  27. : CWindowObject(BORDERED, ImagePath::builtin("DIBOXBCK")), mode { m }, page { 0 }
  28. {
  29. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  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_ACCEPT); //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. video = "tutorial/" + videos[page];
  47. buttonLeft->block(page<1);
  48. buttonRight->block(page>videos.size() - 2);
  49. labelInformation->setText(CGI->generaltexth->translate("vcmi.tutorialWindow.decription." + videos[page]));
  50. }
  51. void CTutorialWindow::openWindowFirstTime(const TutorialMode & m)
  52. {
  53. if(GH.input().hasTouchInputDevice() && !persistentStorage["gui"]["tutorialCompleted" + std::to_string(m)].Bool())
  54. {
  55. if(LOCPLINT)
  56. LOCPLINT->showingDialog->setBusy();
  57. GH.windows().pushWindow(std::make_shared<CTutorialWindow>(m));
  58. Settings s = persistentStorage.write["gui"]["tutorialCompleted" + std::to_string(m)];
  59. s->Bool() = true;
  60. }
  61. }
  62. void CTutorialWindow::exit()
  63. {
  64. if(LOCPLINT)
  65. LOCPLINT->showingDialog->setFree();
  66. close();
  67. }
  68. void CTutorialWindow::next()
  69. {
  70. page++;
  71. setContent();
  72. deactivate();
  73. activate();
  74. }
  75. void CTutorialWindow::previous()
  76. {
  77. page--;
  78. setContent();
  79. deactivate();
  80. activate();
  81. }
  82. void CTutorialWindow::show(Canvas & to)
  83. {
  84. CCS->videoh->update(pos.x + 30, pos.y + 120, to.getInternalSurface(), true, false,
  85. [&]()
  86. {
  87. CCS->videoh->close();
  88. CCS->videoh->open(VideoPath::builtin(video));
  89. });
  90. CIntObject::show(to);
  91. }
  92. void CTutorialWindow::activate()
  93. {
  94. CCS->videoh->open(VideoPath::builtin(video));
  95. CIntObject::activate();
  96. }
  97. void CTutorialWindow::deactivate()
  98. {
  99. CCS->videoh->close();
  100. }