CTutorialWindow.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "../../lib/CondSh.h"
  15. #include "../CPlayerInterface.h"
  16. #include "../CGameInfo.h"
  17. #include "../CVideoHandler.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 "../render/Canvas.h"
  25. CTutorialWindow::CTutorialWindow(const TutorialMode & m)
  26. : CWindowObject(BORDERED, ImagePath::builtin("DIBOXBCK")), mode { m }, page { 0 }
  27. {
  28. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  29. pos = Rect(pos.x, pos.y, 380, 400); //video: 320x240
  30. background = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, pos.w, pos.h));
  31. updateShadow();
  32. center();
  33. addUsedEvents(LCLICK);
  34. if(mode == TutorialMode::TOUCH_ADVENTUREMAP) videos = { "RightClick", "MapPanning", "MapZooming" };
  35. else if(mode == TutorialMode::TOUCH_BATTLE) videos = { "BattleDirection", "BattleDirectionAbort", "AbortSpell" };
  36. labelTitle = std::make_shared<CLabel>(190, 15, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, "Touchscreen Intro");
  37. buttonOk = std::make_shared<CButton>(Point(159, 367), AnimationPath::builtin("IOKAY"), CButton::tooltip(), std::bind(&CTutorialWindow::close, this), EShortcut::GLOBAL_ACCEPT); //62x28
  38. buttonLeft = std::make_shared<CButton>(Point(5, 217), AnimationPath::builtin("HSBTNS3"), CButton::tooltip(), std::bind(&CTutorialWindow::previous, this), EShortcut::MOVE_LEFT); //22x46
  39. buttonRight = std::make_shared<CButton>(Point(352, 217), AnimationPath::builtin("HSBTNS5"), CButton::tooltip(), std::bind(&CTutorialWindow::next, this), EShortcut::MOVE_RIGHT); //22x46
  40. setContent();
  41. }
  42. void CTutorialWindow::setContent()
  43. {
  44. video = "tutorial/" + videos[page];
  45. buttonLeft->block(page<1);
  46. buttonRight->block(page>videos.size() - 2);
  47. labelInformation = std::make_shared<CMultiLineLabel>(Rect(5, 40, 370, 60), EFonts::FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.");
  48. }
  49. void CTutorialWindow::openWindowFirstTime(const TutorialMode & m)
  50. {
  51. if(GH.input().hasTouchInputDevice() && !persistentStorage["gui"]["tutorialCompleted" + std::to_string(m)].Bool())
  52. {
  53. if(LOCPLINT)
  54. LOCPLINT->showingDialog->set(true);
  55. GH.windows().pushWindow(std::make_shared<CTutorialWindow>(m));
  56. Settings s = persistentStorage.write["gui"]["tutorialCompleted" + std::to_string(m)];
  57. s->Bool() = true;
  58. }
  59. }
  60. void CTutorialWindow::close()
  61. {
  62. if(LOCPLINT)
  63. LOCPLINT->showingDialog->setn(false);
  64. WindowBase::close();
  65. }
  66. void CTutorialWindow::next()
  67. {
  68. page++;
  69. setContent();
  70. deactivate();
  71. activate();
  72. }
  73. void CTutorialWindow::previous()
  74. {
  75. page--;
  76. setContent();
  77. deactivate();
  78. activate();
  79. }
  80. void CTutorialWindow::show(Canvas & to)
  81. {
  82. CCS->videoh->update(pos.x + 30, pos.y + 120, to.getInternalSurface(), true, false,
  83. [&]()
  84. {
  85. CCS->videoh->close();
  86. CCS->videoh->open(VideoPath::builtin(video));
  87. });
  88. CIntObject::show(to);
  89. }
  90. void CTutorialWindow::activate()
  91. {
  92. CCS->videoh->open(VideoPath::builtin(video));
  93. CIntObject::activate();
  94. }
  95. void CTutorialWindow::deactivate()
  96. {
  97. CCS->videoh->close();
  98. }