CreditsScreen.cpp 2.0 KB

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