CPrologEpilogVideo.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * CPrologEpilogVideo.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 "CPrologEpilogVideo.h"
  12. #include "../CGameInfo.h"
  13. #include "../CMusicHandler.h"
  14. #include "../CVideoHandler.h"
  15. #include "../gui/CGuiHandler.h"
  16. #include "../widgets/TextControls.h"
  17. #include "../render/Canvas.h"
  18. #include "../../lib/mapping/CCampaignHandler.h"
  19. CPrologEpilogVideo::CPrologEpilogVideo(CampaignScenarioPrologEpilog _spe, std::function<void()> callback)
  20. : CWindowObject(BORDERED), spe(_spe), positionCounter(0), voiceSoundHandle(-1), exitCb(callback)
  21. {
  22. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  23. addUsedEvents(LCLICK);
  24. pos = center(Rect(0, 0, 800, 600));
  25. updateShadow();
  26. CCS->videoh->open(spe.prologVideo);
  27. CCS->musich->playMusic("Music/" + spe.prologMusic, true, true);
  28. // MPTODO: Custom campaign crashing on this?
  29. // voiceSoundHandle = CCS->soundh->playSound(CCampaignHandler::prologVoiceName(spe.prologVideo));
  30. text = std::make_shared<CMultiLineLabel>(Rect(100, 500, 600, 100), EFonts::FONT_BIG, ETextAlignment::CENTER, Colors::METALLIC_GOLD, spe.prologText);
  31. text->scrollTextTo(-100);
  32. }
  33. void CPrologEpilogVideo::show(Canvas & to)
  34. {
  35. to.drawColor(pos, Colors::BLACK);
  36. //BUG: some videos are 800x600 in size while some are 800x400
  37. //VCMI should center them in the middle of the screen. Possible but needs modification
  38. //of video player API which I'd like to avoid until we'll get rid of Windows-specific player
  39. CCS->videoh->update(pos.x, pos.y, to.getInternalSurface(), true, false);
  40. //move text every 5 calls/frames; seems to be good enough
  41. ++positionCounter;
  42. if(positionCounter % 5 == 0)
  43. text->scrollTextBy(1);
  44. else
  45. text->showAll(to); // blit text over video, if needed
  46. if(text->textSize.y + 100 < positionCounter / 5)
  47. clickLeft(false, false);
  48. }
  49. void CPrologEpilogVideo::clickLeft(tribool down, bool previousState)
  50. {
  51. close();
  52. CCS->soundh->stopSound(voiceSoundHandle);
  53. exitCb();
  54. }