CPrologEpilogVideo.cpp 2.1 KB

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