CreditsScreen.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "../GameEngine.h"
  14. #include "../widgets/TextControls.h"
  15. #include "../widgets/ObjectLists.h"
  16. #include "../../lib/GameLibrary.h"
  17. #include "../../lib/filesystem/Filesystem.h"
  18. #include "../../lib/texts/CGeneralTextHandler.h"
  19. #include "../../AUTHORS.h"
  20. CreditsScreen::CreditsScreen(Rect rect)
  21. : CIntObject(LCLICK), timePassed(0)
  22. {
  23. pos.w = rect.w;
  24. pos.h = rect.h;
  25. setRedrawParent(true);
  26. OBJECT_CONSTRUCTION;
  27. addUsedEvents(TIME);
  28. std::string contributorsText = "";
  29. std::string contributorsTask = "";
  30. for (auto & element : contributors)
  31. {
  32. if(element[0] != contributorsTask)
  33. contributorsText += "\r\n\r\n{" + LIBRARY->generaltexth->translate("vcmi.credits." + boost::to_lower_copy(element[0])) + ":}\r\n";
  34. contributorsText += (element[2] != "" ? element[2] : element[1]) + "\r\n";
  35. contributorsTask = element[0];
  36. }
  37. auto textFile = CResourceHandler::get()->load(ResourcePath("DATA/CREDITS.TXT"))->readAll();
  38. std::string text((char *)textFile.first.get(), textFile.second);
  39. size_t firstQuote = text.find('\"') + 1;
  40. text = text.substr(firstQuote, text.find('\"', firstQuote) - firstQuote);
  41. text = "{- " + LIBRARY->generaltexth->translate("vcmi.credits.vcmi") + " -}\r\n" + contributorsText + "\r\n\r\n{" + LIBRARY->generaltexth->translate("vcmi.credits.website") + ":}\r\nhttps://vcmi.eu\r\n\r\n\r\n\r\n\r\n{- " + LIBRARY->generaltexth->translate("vcmi.credits.heroes") + " -}\r\n\r\n\r\n" + text;
  42. credits = std::make_shared<CMultiLineLabel>(Rect(pos.w - 350, 0, 350, 600), FONT_CREDITS, ETextAlignment::CENTER, Colors::WHITE, text);
  43. credits->scrollTextTo(-600); // move all text below the screen
  44. }
  45. void CreditsScreen::tick(uint32_t msPassed)
  46. {
  47. static const int timeToScrollByOnePx = 20;
  48. timePassed += msPassed;
  49. int scrollPosition = timePassed / timeToScrollByOnePx - 600;
  50. credits->scrollTextTo(scrollPosition);
  51. //end of credits, close this screen
  52. if(credits->textSize.y < scrollPosition)
  53. clickPressed(ENGINE->getCursorPosition());
  54. }
  55. void CreditsScreen::clickPressed(const Point & cursorPosition)
  56. {
  57. CTabbedInt * menu = dynamic_cast<CTabbedInt *>(parent);
  58. assert(menu);
  59. menu->setActive(0);
  60. }