CreditsScreen.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 | RCLICK), positionCounter(0)
  19. {
  20. pos.w = rect.w;
  21. pos.h = rect.h;
  22. type |= REDRAW_PARENT;
  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, CENTER, Colors::WHITE, text);
  29. credits->scrollTextTo(-600); // move all text below the screen
  30. }
  31. void CreditsScreen::show(SDL_Surface * 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. clickRight(false, false);
  40. }
  41. void CreditsScreen::clickLeft(tribool down, bool previousState)
  42. {
  43. clickRight(down, previousState);
  44. }
  45. void CreditsScreen::clickRight(tribool down, bool previousState)
  46. {
  47. CTabbedInt * menu = dynamic_cast<CTabbedInt *>(parent);
  48. assert(menu);
  49. menu->setActive(0);
  50. }