CreditsScreen.cpp 2.1 KB

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