CreditsScreen.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * CreditsScreen.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 "CreditsScreen.h"
  12. #include "CMainMenu.h"
  13. #include "../gui/CGuiHandler.h"
  14. #include "../widgets/TextControls.h"
  15. #include "../widgets/ObjectLists.h"
  16. #include "../../lib/filesystem/Filesystem.h"
  17. CreditsScreen::CreditsScreen(Rect rect)
  18. : CIntObject(LCLICK), positionCounter(0)
  19. {
  20. pos.w = rect.w;
  21. pos.h = rect.h;
  22. setRedrawParent(true);
  23. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  24. auto textFile = CResourceHandler::get()->load(ResourceID("DATA/CREDITS.TXT"))->readAll();
  25. std::string text((char *)textFile.first.get(), textFile.second);
  26. size_t firstQuote = text.find('\"') + 1;
  27. text = text.substr(firstQuote, text.find('\"', firstQuote) - firstQuote);
  28. credits = std::make_shared<CMultiLineLabel>(Rect(pos.w - 350, 0, 350, 600), FONT_CREDITS, ETextAlignment::CENTER, Colors::WHITE, text);
  29. credits->scrollTextTo(-600); // move all text below the screen
  30. }
  31. void CreditsScreen::show(Canvas & to)
  32. {
  33. CIntObject::show(to);
  34. positionCounter++;
  35. if(positionCounter % 2 == 0)
  36. credits->scrollTextBy(1);
  37. //end of credits, close this screen
  38. if(credits->textSize.y + 600 < positionCounter / 2)
  39. clickPressed(GH.getCursorPosition());
  40. }
  41. void CreditsScreen::clickPressed(const Point & cursorPosition)
  42. {
  43. CTabbedInt * menu = dynamic_cast<CTabbedInt *>(parent);
  44. assert(menu);
  45. menu->setActive(0);
  46. }