CreditsScreen.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(ResourcePath("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. text = "{- VCMI -}\r\n\r\n{Contributors:}\r\n" + boost::algorithm::join(contributors, "\r\n") + "\r\n\r\n{Website:}\r\nhttps://vcmi.eu\r\n\r\n\r\n\r\n\r\n{- Heroes of Might and Magic III -}\r\n\r\n" + text;
  29. credits = std::make_shared<CMultiLineLabel>(Rect(pos.w - 350, 0, 350, 600), FONT_CREDITS, ETextAlignment::CENTER, Colors::WHITE, text);
  30. credits->scrollTextTo(-600); // move all text below the screen
  31. }
  32. void CreditsScreen::show(Canvas & to)
  33. {
  34. CIntObject::show(to);
  35. positionCounter++;
  36. if(positionCounter % 2 == 0)
  37. credits->scrollTextBy(1);
  38. //end of credits, close this screen
  39. if(credits->textSize.y + 600 < positionCounter / 2)
  40. clickPressed(GH.getCursorPosition());
  41. }
  42. void CreditsScreen::clickPressed(const Point & cursorPosition)
  43. {
  44. CTabbedInt * menu = dynamic_cast<CTabbedInt *>(parent);
  45. assert(menu);
  46. menu->setActive(0);
  47. }